Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/buildsystem3/src/tolua/lua/compat.lua @ 2708

Last change on this file since 2708 was 2664, checked in by rgrieder, 16 years ago

Merged buildsystem2 to buildsystem3.

Note: Bare merge, just resolved conflicts. To testing, no nothing.

  • Property svn:eol-style set to native
File size: 4.1 KB
Line 
1-------------------------------------------------------------------
2-- Real globals
3-- _ALERT
4-- _ERRORMESSAGE
5-- _VERSION
6-- _G
7-- assert
8-- error
9-- metatable
10-- next
11-- print
12-- require
13-- tonumber
14-- tostring
15-- type
16-- unpack
17
18-------------------------------------------------------------------
19-- collectgarbage
20-- gcinfo
21
22-- globals
23
24-- call   -> protect(f, err)
25-- loadfile
26-- loadstring
27
28-- rawget
29-- rawset
30
31-- getargs = Main.getargs ??
32
33rawtype = type
34
35function do_ (f, err)
36    if not f then print(err); return end
37    local a,b = pcall(f)
38    if not a then print(b); return nil
39    else return b or true
40    end
41end
42
43function dostring(s) return do_(loadstring(s)) end
44-- function dofile(s) return do_(loadfile(s)) end
45
46-------------------------------------------------------------------
47-- Table library
48local tab = table
49foreach = tab.foreach
50foreachi = tab.foreachi
51getn = tab.getn
52tinsert = tab.insert
53tremove = tab.remove
54sort = tab.sort
55
56-------------------------------------------------------------------
57-- Debug library
58local dbg = debug
59getinfo = dbg.getinfo
60getlocal = dbg.getlocal
61setcallhook = function () error"`setcallhook' is deprecated" end
62setlinehook = function () error"`setlinehook' is deprecated" end
63setlocal = dbg.setlocal
64
65-------------------------------------------------------------------
66-- math library
67local math = math
68abs = math.abs
69acos = function (x) return math.deg(math.acos(x)) end
70asin = function (x) return math.deg(math.asin(x)) end
71atan = function (x) return math.deg(math.atan(x)) end
72atan2 = function (x,y) return math.deg(math.atan2(x,y)) end
73ceil = math.ceil
74cos = function (x) return math.cos(math.rad(x)) end
75deg = math.deg
76exp = math.exp
77floor = math.floor
78frexp = math.frexp
79ldexp = math.ldexp
80log = math.log
81log10 = math.log10
82max = math.max
83min = math.min
84mod = math.mod
85PI = math.pi
86--??? pow = math.pow 
87rad = math.rad
88random = math.random
89randomseed = math.randomseed
90sin = function (x) return math.sin(math.rad(x)) end
91sqrt = math.sqrt
92tan = function (x) return math.tan(math.rad(x)) end
93
94-------------------------------------------------------------------
95-- string library
96local str = string
97strbyte = str.byte
98strchar = str.char
99strfind = str.find
100format = str.format
101gsub = str.gsub
102strlen = str.len
103strlower = str.lower
104strrep = str.rep
105strsub = str.sub
106strupper = str.upper
107
108-------------------------------------------------------------------
109-- os library
110clock = os.clock
111date = os.date
112difftime = os.difftime
113execute = os.execute --?
114exit = os.exit
115getenv = os.getenv
116remove = os.remove
117rename = os.rename
118setlocale = os.setlocale
119time = os.time
120tmpname = os.tmpname
121
122-------------------------------------------------------------------
123-- compatibility only
124getglobal = function (n) return _G[n] end
125setglobal = function (n,v) _G[n] = v end
126
127-------------------------------------------------------------------
128
129local io, tab = io, table
130
131-- IO library (files)
132_STDIN = io.stdin
133_STDERR = io.stderr
134_STDOUT = io.stdout
135_INPUT = io.stdin
136_OUTPUT = io.stdout
137seek = io.stdin.seek   -- sick ;-)
138tmpfile = io.tmpfile
139closefile = io.close
140openfile = io.open
141
142function flush (f)
143    if f then f:flush()
144    else _OUTPUT:flush()
145    end
146end
147
148function readfrom (name)
149    if name == nil then
150        local f, err, cod = io.close(_INPUT)
151        _INPUT = io.stdin
152        return f, err, cod
153    else
154        local f, err, cod = io.open(name, "r")
155        _INPUT = f or _INPUT
156        return f, err, cod
157    end
158end
159
160function writeto (name)
161    if name == nil then
162        local f, err, cod = io.close(_OUTPUT)
163        _OUTPUT = io.stdout
164        return f, err, cod
165    else
166        local f, err, cod = io.open(name, "w")
167        _OUTPUT = f or _OUTPUT
168        return f, err, cod
169    end
170end
171
172function appendto (name)
173    local f, err, cod = io.open(name, "a")
174    _OUTPUT = f or _OUTPUT
175    return f, err, cod
176end
177
178function read (...)
179    local f = _INPUT
180    if rawtype(arg[1]) == 'userdata' then
181        f = tab.remove(arg, 1)
182    end
183    return f:read(unpack(arg))
184end
185
186function write (...)
187    local f = _OUTPUT
188    if rawtype(arg[1]) == 'userdata' then
189        f = tab.remove(arg, 1)
190    end
191    return f:write(unpack(arg))
192end
193
Note: See TracBrowser for help on using the repository browser.