root/trunk/lua/lua.d

Revision 324, 9.5 kB (checked in by Trass3r, 3 years ago)

+ D2 compatibility!
+ precompiled lua 5.1.4
+ Exceptions support file and line arguments
* changed file encoding to UTF-8
* several bugfixes

Line 
1 module lua.lua;
2
3 private import lua.common;
4 private import lua.luaconf, lua.lauxlib;
5
6 extern (C):
7
8 const LUA_VERSION = "Lua 5.1";
9 const LUA_RELEASE = "Lua 5.1.4";
10 const LUA_VERSION_NUM = 501;
11 const LUA_COPYRIGHT = "Copyright (C) 1994-2008 Lua.org, PUC-Rio";
12 const LUA_AUTHORS = "R. Ierusalimschy, L. H. de Figueiredo & W. Celes";
13
14
15 // mark for precompiled code (`<esc>Lua')
16 const LUA_SIGNATURE = "\033Lua";
17
18 // option for multiple returns in `lua_pcall' and `lua_call'
19 const LUA_MULTRET = -1;
20
21
22 // pseudo-indices
23 const LUA_REGISTRYINDEX = -10000;
24 const LUA_ENVIRONINDEX = -10001;
25 const LUA_GLOBALSINDEX = -10002;
26
27 int lua_upvalueindex (int i) { return LUA_GLOBALSINDEX-i; }
28
29
30 // thread status; 0 is OK
31 const LUA_YIELD = 1;
32 const LUA_ERRRUN = 2;
33 const LUA_ERRSYNTAX = 3;
34 const LUA_ERRMEM = 4;
35 const LUA_ERRERR = 5;
36 const LUA_ERRFILE = LUA_ERRERR+1;
37
38 // don't specify lua_State in detail
39 alias void* lua_State;
40
41 typedef int  function(lua_State *L)lua_CFunction;
42
43
44 // functions that read/write blocks when loading/dumping Lua chunks
45 alias char * function(lua_State *L, void *ud, size_t *sz)lua_Reader;
46 alias int function(lua_State *L, void *p, size_t sz, void *ud)lua_Writer;
47
48 // prototype for memory-allocation functions
49 alias void * function(void *ud, void *ptr, size_t osize, size_t nsize)lua_Alloc;
50
51 // basic types
52 const LUA_TNONE = -1;
53 const LUA_TNIL = 0;
54 const LUA_TBOOLEAN = 1;
55 const LUA_TLIGHTUSERDATA = 2;
56 const LUA_TNUMBER = 3;
57 const LUA_TSTRING = 4;
58 const LUA_TTABLE = 5;
59 const LUA_TFUNCTION = 6;
60 const LUA_TUSERDATA = 7;
61 const LUA_TTHREAD = 8;
62
63 const LUA_MINSTACK = 20;
64
65 // type of numbers in Lua */
66 alias double lua_Number;
67 alias ptrdiff_t lua_Integer;
68
69 // state manipulation
70 lua_State * lua_newstate(lua_Alloc f, void *ud);
71 void  lua_close(lua_State *L);
72 lua_State * lua_newthread(lua_State *L);
73 lua_CFunction  lua_atpanic(lua_State *L, lua_CFunction panicf);
74
75
76 // basic stack manipulation
77 int  lua_gettop(lua_State *L);
78 void  lua_settop(lua_State *L, int idx);
79 void  lua_pushvalue(lua_State *L, int idx);
80 void  lua_remove(lua_State *L, int idx);
81 void  lua_insert(lua_State *L, int idx);
82 void  lua_replace(lua_State *L, int idx);
83 int  lua_checkstack(lua_State *L, int sz);
84
85 void  lua_xmove(lua_State *from, lua_State *to, int n);
86
87
88 // access functions (stack -> C)
89 int  lua_isnumber(lua_State *L, int idx);
90 int  lua_isstring(lua_State *L, int idx);
91 int  lua_iscfunction(lua_State *L, int idx);
92 int  lua_isuserdata(lua_State *L, int idx);
93 int  lua_type(lua_State *L, int idx);
94 ichar * lua_typename(lua_State *L, int tp);
95 int  lua_equal(lua_State *L, int idx1, int idx2);
96 int  lua_rawequal(lua_State *L, int idx1, int idx2);
97 int  lua_lessthan(lua_State *L, int idx1, int idx2);
98
99 lua_Number  lua_tonumber(lua_State *L, int idx);
100 lua_Integer  lua_tointeger(lua_State *L, int idx);
101 int  lua_toboolean(lua_State *L, int idx);
102 ichar * lua_tolstring(lua_State *L, int idx, size_t *len);
103 size_t  lua_objlen(lua_State *L, int idx);
104 lua_CFunction  lua_tocfunction(lua_State *L, int idx);
105 void * lua_touserdata(lua_State *L, int idx);
106 lua_State * lua_tothread(lua_State *L, int idx);
107 void * lua_topointer(lua_State *L, int idx);
108
109
110 // push functions (C -> stack)
111 void  lua_pushnil(lua_State *L);
112 void  lua_pushnumber(lua_State *L, lua_Number n);
113 void  lua_pushinteger(lua_State *L, lua_Integer n);
114 void  lua_pushlstring(lua_State *L, cchar *s, size_t l);
115 void  lua_pushstring(lua_State *L, cchar *s);
116 ichar * lua_pushvfstring(lua_State *L, cchar *fmt, ...);
117 ichar * lua_pushfstring(lua_State *L, cchar *fmt,...);
118 void  lua_pushcclosure(lua_State *L, lua_CFunction fn, int n);
119 void  lua_pushboolean(lua_State *L, int b);
120 void  lua_pushlightuserdata(lua_State *L, void *p);
121 int  lua_pushthread(lua_State *L);
122
123 // get functions (Lua -> stack)
124 void  lua_gettable(lua_State *L, int idx);
125 void  lua_getfield(lua_State *L, int idx, cchar *k);
126 void  lua_rawget(lua_State *L, int idx);
127 void  lua_rawgeti(lua_State *L, int idx, int n);
128 void  lua_createtable(lua_State *L, int narr, int nrec);
129 void * lua_newuserdata(lua_State *L, size_t sz);
130 int  lua_getmetatable(lua_State *L, int objindex);
131 void  lua_getfenv(lua_State *L, int idx);
132
133 // set functions (stack -> Lua)
134 void  lua_settable(lua_State *L, int idx);
135 void  lua_setfield(lua_State *L, int idx, cchar *k);
136 void  lua_rawset(lua_State *L, int idx);
137 void  lua_rawseti(lua_State *L, int idx, int n);
138 int  lua_setmetatable(lua_State *L, int objindex);
139 int  lua_setfenv(lua_State *L, int idx);
140
141 // `load' and `call' functions (load and run Lua code)
142 void  lua_call(lua_State *L, int nargs, int nresults);
143 int  lua_pcall(lua_State *L, int nargs, int nresults, int errfunc);
144 int  lua_cpcall(lua_State *L, lua_CFunction func, void *ud);
145 int  lua_load(lua_State *L, lua_Reader reader, void *dt, cchar *chunkname);
146 int  lua_dump(lua_State *L, lua_Writer writer, void *data);
147
148
149 // coroutine functions
150 int  lua_yield(lua_State *L, int nresults);
151 int  lua_resume(lua_State *L, int narg);
152 int  lua_status(lua_State *L);
153
154 // garbage-collection function and options
155 const LUA_GCSTOP = 0;
156 const LUA_GCRESTART = 1;
157 const LUA_GCCOLLECT = 2;
158 const LUA_GCCOUNT = 3;
159 const LUA_GCCOUNTB = 4;
160 const LUA_GCSTEP = 5;
161 const LUA_GCSETPAUSE = 6;
162 const LUA_GCSETSTEPMUL = 7;
163
164 int  lua_gc(lua_State *L, int what, int data);
165
166
167 // miscellaneous functions
168 int  lua_error(lua_State *L);
169 int  lua_next(lua_State *L, int idx);
170 void  lua_concat(lua_State *L, int n);
171 lua_Alloc  lua_getallocf(lua_State *L, void **ud);
172 void  lua_setallocf(lua_State *L, lua_Alloc f, void *ud);
173
174 // some useful macros
175 void lua_pop(lua_State* L, int n) { lua_settop(L, -(n)-1); }
176 void lua_newtable(lua_State* L) { lua_createtable(L, 0, 0); }
177 void lua_register(lua_State* L, char* n, lua_CFunction f) { lua_pushcfunction(L, f); lua_setglobal(L, n); }
178 void lua_pushcfunction(lua_State* L, lua_CFunction f) { lua_pushcclosure(L, f, 0); }
179 int lua_strlen(lua_State* L, int i) { return lua_objlen(L, i); }
180 bool lua_isfunction(lua_State* L, int n) { return lua_type(L, n) == LUA_TFUNCTION; }
181 bool lua_istable(lua_State* L, int n) { return lua_type(L, n) == LUA_TTABLE; }
182 bool lua_islightuserdata(lua_State* L, int n) { return lua_type(L, n) == LUA_TLIGHTUSERDATA; }
183 bool lua_isnil(lua_State* L, int n) { return lua_type(L, n) == LUA_TNIL; }
184 bool lua_isboolean(lua_State* L, int n) { return lua_type(L, n) == LUA_TBOOLEAN; }
185 bool lua_isthread(lua_State* L, int n) { return lua_type(L, n) == LUA_TTHREAD; }
186 bool lua_isnone(lua_State* L, int n) { return lua_type(L, n) == LUA_TNONE; }
187 bool lua_isnoneornil(lua_State* L, int n) { return lua_type(L, n) <= 0; }
188 void lua_pushliteral(lua_State* L, char[] s) { lua_pushlstring(L, (s ~ \0).ptr, s.length);  }
189 void lua_setglobal(lua_State* L, char* s) { lua_setfield(L, LUA_GLOBALSINDEX, s); }
190 void lua_getglobal(lua_State* L, char* s) { lua_getfield(L, LUA_GLOBALSINDEX, s); }
191 ichar* lua_tostring(lua_State* L, int i) { return lua_tolstring(L, i, null); }
192
193 // compatibility macros and functions
194 lua_State* lua_open() { return luaL_newstate(); }
195 void lua_getregistry(lua_State* L) { lua_pushvalue(L, LUA_REGISTRYINDEX); }
196 int lua_getgccount(lua_State* L) { return lua_gc(L, LUA_GCCOUNT, 0); }
197 alias lua_Reader lua_Chunkreader;
198 alias lua_Writer lua_Chunkwriter;
199
200 // hack
201 void lua_setlevel (lua_State *from, lua_State *to);
202
203
204 // Debug API
205
206 // Event codes
207 const LUA_HOOKCALL = 0;
208 const LUA_HOOKRET = 1;
209 const LUA_HOOKLINE = 2;
210 const LUA_HOOKCOUNT = 3;
211 const LUA_HOOKTAILRET = 4;
212
213 // Event masks
214 const LUA_MASKCALL = 1 << LUA_HOOKCALL;
215 const LUA_MASKRET = 1 << LUA_HOOKRET;
216 const LUA_MASKLINE = 1 << LUA_HOOKLINE;
217 const LUA_MASKCOUNT = 1 << LUA_HOOKCOUNT;
218
219 alias void  function(lua_State *L, lua_Debug *ar)lua_Hook;
220
221 int  lua_getstack(lua_State *L, int level, lua_Debug *ar);
222 int  lua_getinfo(lua_State *L, cchar *what, lua_Debug *ar);
223 ichar * lua_getlocal(lua_State *L, lua_Debug *ar, int n);
224 ichar * lua_setlocal(lua_State *L, lua_Debug *ar, int n);
225 ichar * lua_getupvalue(lua_State *L, int funcindex, int n);
226 ichar * lua_setupvalue(lua_State *L, int funcindex, int n);
227 int  lua_sethook(lua_State *L, lua_Hook func, int mask, int count);
228 lua_Hook  lua_gethook(lua_State *L);
229 int  lua_gethookmask(lua_State *L);
230 int  lua_gethookcount(lua_State *L);
231
232 struct lua_Debug
233 {
234     int event;
235     char *name;
236     char *namewhat;
237     char *what;
238     char *source;
239     int currentline;
240     int nups;
241     int linedefined;
242     int lastlinedefined;
243     char [LUA_IDSIZE]short_src;
244     int i_ci;
245 }
246
247 /******************************************************************************
248 * Copyright (C) 1994-2008 Lua.org, PUC-Rio.  All rights reserved.
249 *
250 * Permission is hereby granted, free of charge, to any person obtaining
251 * a copy of this software and associated documentation files (the
252 * "Software"), to deal in the Software without restriction, including
253 * without limitation the rights to use, copy, modify, merge, publish,
254 * distribute, sublicense, and/or sell copies of the Software, and to
255 * permit persons to whom the Software is furnished to do so, subject to
256 * the following conditions:
257 *
258 * The above copyright notice and this permission notice shall be
259 * included in all copies or substantial portions of the Software.
260 *
261 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
262 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
263 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
264 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
265 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
266 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
267 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
268 ******************************************************************************/
Note: See TracBrowser for help on using the browser.