14 |
14 |
15 |
15 |
16 #include "luaconf.h" |
16 #include "luaconf.h" |
17 |
17 |
18 |
18 |
19 #define LUA_VERSION "Lua 5.1" |
19 #define LUA_VERSION "Lua 5.1" |
20 #define LUA_RELEASE "Lua 5.1.4" |
20 #define LUA_RELEASE "Lua 5.1.4" |
21 #define LUA_VERSION_NUM 501 |
21 #define LUA_VERSION_NUM 501 |
22 #define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" |
22 #define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" |
23 #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" |
23 #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" |
24 |
24 |
25 |
25 |
26 /* mark for precompiled code (`<esc>Lua') */ |
26 /* mark for precompiled code (`<esc>Lua') */ |
27 #define LUA_SIGNATURE "\033Lua" |
27 #define LUA_SIGNATURE "\033Lua" |
28 |
28 |
29 /* option for multiple returns in `lua_pcall' and `lua_call' */ |
29 /* option for multiple returns in `lua_pcall' and `lua_call' */ |
30 #define LUA_MULTRET (-1) |
30 #define LUA_MULTRET (-1) |
31 |
31 |
32 |
32 |
33 /* |
33 /* |
34 ** pseudo-indices |
34 ** pseudo-indices |
35 */ |
35 */ |
36 #define LUA_REGISTRYINDEX (-10000) |
36 #define LUA_REGISTRYINDEX (-10000) |
37 #define LUA_ENVIRONINDEX (-10001) |
37 #define LUA_ENVIRONINDEX (-10001) |
38 #define LUA_GLOBALSINDEX (-10002) |
38 #define LUA_GLOBALSINDEX (-10002) |
39 #define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) |
39 #define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) |
40 |
40 |
41 |
41 |
42 /* thread status; 0 is OK */ |
42 /* thread status; 0 is OK */ |
43 #define LUA_YIELD 1 |
43 #define LUA_YIELD 1 |
44 #define LUA_ERRRUN 2 |
44 #define LUA_ERRRUN 2 |
45 #define LUA_ERRSYNTAX 3 |
45 #define LUA_ERRSYNTAX 3 |
46 #define LUA_ERRMEM 4 |
46 #define LUA_ERRMEM 4 |
47 #define LUA_ERRERR 5 |
47 #define LUA_ERRERR 5 |
48 |
48 |
49 |
49 |
50 typedef struct lua_State lua_State; |
50 typedef struct lua_State lua_State; |
51 |
51 |
52 typedef int (*lua_CFunction) (lua_State *L); |
52 typedef int (*lua_CFunction) (lua_State *L); |
147 LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx); |
147 LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx); |
148 LUA_API int (lua_toboolean) (lua_State *L, int idx); |
148 LUA_API int (lua_toboolean) (lua_State *L, int idx); |
149 LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); |
149 LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); |
150 LUA_API size_t (lua_objlen) (lua_State *L, int idx); |
150 LUA_API size_t (lua_objlen) (lua_State *L, int idx); |
151 LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); |
151 LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); |
152 LUA_API void *(lua_touserdata) (lua_State *L, int idx); |
152 LUA_API void *(lua_touserdata) (lua_State *L, int idx); |
153 LUA_API lua_State *(lua_tothread) (lua_State *L, int idx); |
153 LUA_API lua_State *(lua_tothread) (lua_State *L, int idx); |
154 LUA_API const void *(lua_topointer) (lua_State *L, int idx); |
154 LUA_API const void *(lua_topointer) (lua_State *L, int idx); |
155 |
155 |
156 |
156 |
157 /* |
157 /* |
249 ** =============================================================== |
249 ** =============================================================== |
250 ** some useful macros |
250 ** some useful macros |
251 ** =============================================================== |
251 ** =============================================================== |
252 */ |
252 */ |
253 |
253 |
254 #define lua_pop(L,n) lua_settop(L, -(n)-1) |
254 #define lua_pop(L,n) lua_settop(L, -(n)-1) |
255 |
255 |
256 #define lua_newtable(L) lua_createtable(L, 0, 0) |
256 #define lua_newtable(L) lua_createtable(L, 0, 0) |
257 |
257 |
258 #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) |
258 #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) |
259 |
259 |
260 #define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) |
260 #define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) |
261 |
261 |
262 #define lua_strlen(L,i) lua_objlen(L, (i)) |
262 #define lua_strlen(L,i) lua_objlen(L, (i)) |
263 |
263 |
264 #define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) |
264 #define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) |
265 #define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) |
265 #define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) |
266 #define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) |
266 #define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) |
267 #define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) |
267 #define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) |
268 #define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) |
268 #define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) |
269 #define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) |
269 #define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) |
270 #define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) |
270 #define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) |
271 #define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) |
271 #define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) |
272 |
272 |
273 #define lua_pushliteral(L, s) \ |
273 #define lua_pushliteral(L, s) \ |
274 lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) |
274 lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) |
275 |
275 |
276 #define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) |
276 #define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) |
277 #define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) |
277 #define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) |
278 |
278 |
279 #define lua_tostring(L,i) lua_tolstring(L, (i), NULL) |
279 #define lua_tostring(L,i) lua_tolstring(L, (i), NULL) |
280 |
280 |
281 |
281 |
282 |
282 |
283 /* |
283 /* |
284 ** compatibility macros and functions |
284 ** compatibility macros and functions |
285 */ |
285 */ |
286 |
286 |
287 #define lua_open() luaL_newstate() |
287 #define lua_open() luaL_newstate() |
288 |
288 |
289 #define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) |
289 #define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) |
290 |
290 |
291 #define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0) |
291 #define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0) |
292 |
292 |
293 #define lua_Chunkreader lua_Reader |
293 #define lua_Chunkreader lua_Reader |
294 #define lua_Chunkwriter lua_Writer |
294 #define lua_Chunkwriter lua_Writer |
295 |
295 |
296 |
296 |
297 /* hack */ |
297 /* hack */ |
298 LUA_API void lua_setlevel (lua_State *from, lua_State *to); |
298 LUA_API void lua_setlevel (lua_State *from, lua_State *to); |
299 |
299 |
300 |
300 |
301 /* |
301 /* |
302 ** {====================================================================== |
302 ** {====================================================================== |
303 ** Debug API |
303 ** Debug API |
306 |
306 |
307 |
307 |
308 /* |
308 /* |
309 ** Event codes |
309 ** Event codes |
310 */ |
310 */ |
311 #define LUA_HOOKCALL 0 |
311 #define LUA_HOOKCALL 0 |
312 #define LUA_HOOKRET 1 |
312 #define LUA_HOOKRET 1 |
313 #define LUA_HOOKLINE 2 |
313 #define LUA_HOOKLINE 2 |
314 #define LUA_HOOKCOUNT 3 |
314 #define LUA_HOOKCOUNT 3 |
315 #define LUA_HOOKTAILRET 4 |
315 #define LUA_HOOKTAILRET 4 |
316 |
316 |
317 |
317 |
318 /* |
318 /* |
319 ** Event masks |
319 ** Event masks |
320 */ |
320 */ |
321 #define LUA_MASKCALL (1 << LUA_HOOKCALL) |
321 #define LUA_MASKCALL (1 << LUA_HOOKCALL) |
322 #define LUA_MASKRET (1 << LUA_HOOKRET) |
322 #define LUA_MASKRET (1 << LUA_HOOKRET) |
323 #define LUA_MASKLINE (1 << LUA_HOOKLINE) |
323 #define LUA_MASKLINE (1 << LUA_HOOKLINE) |
324 #define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) |
324 #define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) |
325 |
325 |
326 typedef struct lua_Debug lua_Debug; /* activation record */ |
326 typedef struct lua_Debug lua_Debug; /* activation record */ |
327 |
327 |
328 |
328 |
329 /* Functions to be called by the debuger in specific events */ |
329 /* Functions to be called by the debuger in specific events */ |
343 LUA_API int lua_gethookcount (lua_State *L); |
343 LUA_API int lua_gethookcount (lua_State *L); |
344 |
344 |
345 |
345 |
346 struct lua_Debug { |
346 struct lua_Debug { |
347 int event; |
347 int event; |
348 const char *name; /* (n) */ |
348 const char *name; /* (n) */ |
349 const char *namewhat; /* (n) `global', `local', `field', `method' */ |
349 const char *namewhat; /* (n) `global', `local', `field', `method' */ |
350 const char *what; /* (S) `Lua', `C', `main', `tail' */ |
350 const char *what; /* (S) `Lua', `C', `main', `tail' */ |
351 const char *source; /* (S) */ |
351 const char *source; /* (S) */ |
352 int currentline; /* (l) */ |
352 int currentline; /* (l) */ |
353 int nups; /* (u) number of upvalues */ |
353 int nups; /* (u) number of upvalues */ |
354 int linedefined; /* (S) */ |
354 int linedefined; /* (S) */ |
355 int lastlinedefined; /* (S) */ |
355 int lastlinedefined; /* (S) */ |
356 char short_src[LUA_IDSIZE]; /* (S) */ |
356 char short_src[LUA_IDSIZE]; /* (S) */ |
357 /* private part */ |
357 /* private part */ |
358 int i_ci; /* active function */ |
358 int i_ci; /* active function */ |
359 }; |
359 }; |
360 |
360 |