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
|
local a = include("autolua.lua")
ART = {}
a.AddLuaSHFolder("shared",true)
a.AddLuaCSFolder("client",true)
a.AddLuaSVFolder("server",false)
GM.Name = "Artery"
GM.Author = "Alexander \"Apickx\" Pickering"
GM.Email = "apickx@cogarr.org"
GM.Website = "cogarr.net"
--Some global functions that are helpful
-- printf
-- assertf
-- curry
-- typecheck
--printf from C
function printf(fmt, ...)
print(string.format(fmt,...))
end
--Assert with a formated string
function assertf(cond, fmt, ...)
assert(cond,string.format(fmt,...))
end
--Curry from lisp, allows you to store variables "in" a function, so you can call it with fewer arguments if you'll be repeating arguments a lot
--Ex:
-- >dbprint = curry(print,"[Debug]")
-- >dbprint("Hello, world!")
-- [Debug] Hello, world!
-- >
function curry(fnc, ...)
local oarg = {...}
return function(...)
return fnc(unpack(oarg),unpack({...}))
end
end
--Does type checking for functions, use by supplying a table whith the variables and the types they should be
--Ex:
-- >local somefunction(str, tbl, num)
-- >>typecheck({
-- >> str,"string",
-- >> tbl,"table",
-- >> num,"number"
-- >>})
-- >
function typecheck(...)
local tbl = {...}
tbl = type(tbl[1]) == "table" and tbl[1] or tbl
for k=1,#tbl,2 do
local t,n = type(tbl[k]),tbl[k+1]
assertf(t == n, "Passed argument of wrong type, should have been %q but was %q",t,n )
end
end
--Add a thing to report errors to a master server
--TODO:Set up a master server to collect errors for correction
local olderr = error
function error(str)
print("I got an error!")
olderr(str)
end
|