-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLuaAdv.lua
More file actions
89 lines (89 loc) · 2.48 KB
/
LuaAdv.lua
File metadata and controls
89 lines (89 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
global=_G; function table.object(self, super) if super then setmetatable(self, super) end; self.__index=self; return self end; function table.super(self, super, ...) return setmetatable(super.new(...), self) end
function table.new(meta, self) return setmetatable(self or {}, meta) end
global. T = table.object({
C = function(...)
local params = {...}
for i, v in pairs(params) do
if (i % 2) ~= 0 and type(v) ~= params[i + 1] then
error("expected '" .. params[i + 1] .. "', got '" .. type(v) .. "'")
end
end
end
})
global. Error = table.object({
Handle = table.object({
Try = function() end;
Catch = function(err) end;
Finally = function() end;
new = function(t) T.C(t, "table")
local self = table.new(Error)
self.Try = t.try or t.Try
self.Catch = t.catch or t.Catch
self.Finally = t.finally or t.Finally
return self
end;
exec = function()
local res, err = pcall(self.Try)
if (not res) then
pcall(self.Catch, err)
pcall(self.Finally)
return err
elseif (res) then
pcall(self.Finally)
return res
end
end;
});
Name = "Error";
Description = "Default error";
Context = nil;
new = function(name, desc, context) T.C(name, "string", desc, "string", context, "table")
local self = table.new(Error)
self.Name = name
self.Description = desc
self.Context = context
return self
end;
print = function(self)
IO.println(
self.Name .. ": " .. self.Description .. "\n" ..
"\t" .. tostring((self.Context or { Name = "Unknown" }).Name)
)
end;
})
global. Program = table.object({
Name = "";
Version = "";
new = function(name, version) T.C(name, "string", version, "string")
local self = table.new(Program)
self.Name = name;
self.Version = version;
return self;
end;
})
global. IO = table.object({
print = function(string, ...) T.C(string, "string")
local tmp = "\t" for i, v in pairs({...}) do
tmp = tmp .. "\t" .. tostring(v)
end
return io.write(string .. tmp)
end;
println = function(string, ...) T.C(string, "string")
local tmp = "\t" for i, v in pairs({...}) do
tmp = tmp .. "\t" .. tostring(v)
end
return print(string .. tmp)
end;
ln = function()
print()
end;
readInt = function()
return tonumber(io.read())
end;
readChar = function()
return string.sub(tostring(io.read()), 1, 1)
end;
readString = function()
return tostring(io.read())
end;
})