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