16#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2025 Lua.org, PUC-Rio"
17#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
20#define LUA_VERSION_MAJOR_N 5
21#define LUA_VERSION_MINOR_N 5
22#define LUA_VERSION_RELEASE_N 0
24#define LUA_VERSION_NUM (LUA_VERSION_MAJOR_N * 100 + LUA_VERSION_MINOR_N)
25#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + LUA_VERSION_RELEASE_N)
32#define LUA_SIGNATURE "\x1bLua"
35#define LUA_MULTRET (-1)
43#define LUA_REGISTRYINDEX (-(INT_MAX/2 + 1000))
44#define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i))
51#define LUA_ERRSYNTAX 3
56typedef struct lua_State lua_State;
66#define LUA_TLIGHTUSERDATA 2
70#define LUA_TFUNCTION 6
71#define LUA_TUSERDATA 7
79#define LUA_MINSTACK 20
84#define LUA_RIDX_GLOBALS 2
85#define LUA_RIDX_MAINTHREAD 3
86#define LUA_RIDX_LAST 3
90typedef LUA_NUMBER lua_Number;
94typedef LUA_INTEGER lua_Integer;
97typedef LUA_UNSIGNED lua_Unsigned;
100typedef LUA_KCONTEXT lua_KContext;
106typedef int (*lua_CFunction) (lua_State *L);
111typedef int (*lua_KFunction) (lua_State *L,
int status, lua_KContext ctx);
117typedef const char * (*lua_Reader) (lua_State *L,
void *ud,
size_t *sz);
119typedef int (*lua_Writer) (lua_State *L,
const void *p,
size_t sz,
void *ud);
125typedef void * (*lua_Alloc) (
void *ud,
void *ptr,
size_t osize,
size_t nsize);
131typedef void (*lua_WarnFunction) (
void *ud,
const char *msg,
int tocont);
137typedef struct lua_Debug lua_Debug;
143typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
149#if defined(LUA_USER_H)
157extern const char lua_ident[];
163LUA_API lua_State *(lua_newstate) (lua_Alloc f,
void *ud,
unsigned seed);
164LUA_API void (lua_close) (lua_State *L);
165LUA_API lua_State *(lua_newthread) (lua_State *L);
166LUA_API int (lua_closethread) (lua_State *L, lua_State *from);
168LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
171LUA_API lua_Number (lua_version) (lua_State *L);
177LUA_API int (lua_absindex) (lua_State *L,
int idx);
178LUA_API int (lua_gettop) (lua_State *L);
179LUA_API void (lua_settop) (lua_State *L,
int idx);
180LUA_API void (lua_pushvalue) (lua_State *L,
int idx);
181LUA_API void (lua_rotate) (lua_State *L,
int idx,
int n);
182LUA_API void (lua_copy) (lua_State *L,
int fromidx,
int toidx);
183LUA_API int (lua_checkstack) (lua_State *L,
int n);
185LUA_API void (lua_xmove) (lua_State *from, lua_State *to,
int n);
192LUA_API int (lua_isnumber) (lua_State *L,
int idx);
193LUA_API int (lua_isstring) (lua_State *L,
int idx);
194LUA_API int (lua_iscfunction) (lua_State *L,
int idx);
195LUA_API int (lua_isinteger) (lua_State *L,
int idx);
196LUA_API int (lua_isuserdata) (lua_State *L,
int idx);
197LUA_API int (lua_type) (lua_State *L,
int idx);
198LUA_API
const char *(lua_typename) (lua_State *L,
int tp);
200LUA_API lua_Number (lua_tonumberx) (lua_State *L,
int idx,
int *isnum);
201LUA_API lua_Integer (lua_tointegerx) (lua_State *L,
int idx,
int *isnum);
202LUA_API int (lua_toboolean) (lua_State *L,
int idx);
203LUA_API
const char *(lua_tolstring) (lua_State *L,
int idx,
size_t *len);
204LUA_API lua_Unsigned (lua_rawlen) (lua_State *L,
int idx);
205LUA_API lua_CFunction (lua_tocfunction) (lua_State *L,
int idx);
206LUA_API
void *(lua_touserdata) (lua_State *L,
int idx);
207LUA_API lua_State *(lua_tothread) (lua_State *L,
int idx);
208LUA_API
const void *(lua_topointer) (lua_State *L,
int idx);
230LUA_API void (lua_arith) (lua_State *L,
int op);
236LUA_API int (lua_rawequal) (lua_State *L,
int idx1,
int idx2);
237LUA_API int (lua_compare) (lua_State *L,
int idx1,
int idx2,
int op);
243LUA_API void (lua_pushnil) (lua_State *L);
244LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
245LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
246LUA_API
const char *(lua_pushlstring) (lua_State *L,
const char *s,
size_t len);
247LUA_API
const char *(lua_pushexternalstring) (lua_State *L,
248 const char *s,
size_t len, lua_Alloc falloc,
void *ud);
249LUA_API
const char *(lua_pushstring) (lua_State *L,
const char *s);
250LUA_API
const char *(lua_pushvfstring) (lua_State *L,
const char *fmt,
252LUA_API
const char *(lua_pushfstring) (lua_State *L,
const char *fmt, ...);
253LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn,
int n);
254LUA_API void (lua_pushboolean) (lua_State *L,
int b);
255LUA_API void (lua_pushlightuserdata) (lua_State *L,
void *p);
256LUA_API int (lua_pushthread) (lua_State *L);
262LUA_API int (lua_getglobal) (lua_State *L,
const char *name);
263LUA_API int (lua_gettable) (lua_State *L,
int idx);
264LUA_API int (lua_getfield) (lua_State *L,
int idx,
const char *k);
265LUA_API int (lua_geti) (lua_State *L,
int idx, lua_Integer n);
266LUA_API int (lua_rawget) (lua_State *L,
int idx);
267LUA_API int (lua_rawgeti) (lua_State *L,
int idx, lua_Integer n);
268LUA_API int (lua_rawgetp) (lua_State *L,
int idx,
const void *p);
270LUA_API void (lua_createtable) (lua_State *L,
int narr,
int nrec);
271LUA_API
void *(lua_newuserdatauv) (lua_State *L,
size_t sz,
int nuvalue);
272LUA_API int (lua_getmetatable) (lua_State *L,
int objindex);
273LUA_API int (lua_getiuservalue) (lua_State *L,
int idx,
int n);
279LUA_API void (lua_setglobal) (lua_State *L,
const char *name);
280LUA_API void (lua_settable) (lua_State *L,
int idx);
281LUA_API void (lua_setfield) (lua_State *L,
int idx,
const char *k);
282LUA_API void (lua_seti) (lua_State *L,
int idx, lua_Integer n);
283LUA_API void (lua_rawset) (lua_State *L,
int idx);
284LUA_API void (lua_rawseti) (lua_State *L,
int idx, lua_Integer n);
285LUA_API void (lua_rawsetp) (lua_State *L,
int idx,
const void *p);
286LUA_API int (lua_setmetatable) (lua_State *L,
int objindex);
287LUA_API int (lua_setiuservalue) (lua_State *L,
int idx,
int n);
293LUA_API void (lua_callk) (lua_State *L,
int nargs,
int nresults,
294 lua_KContext ctx, lua_KFunction k);
295#define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL)
297LUA_API int (lua_pcallk) (lua_State *L,
int nargs,
int nresults,
int errfunc,
298 lua_KContext ctx, lua_KFunction k);
299#define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL)
301LUA_API int (lua_load) (lua_State *L, lua_Reader reader,
void *dt,
302 const char *chunkname,
const char *mode);
304LUA_API int (lua_dump) (lua_State *L, lua_Writer writer,
void *data,
int strip);
310LUA_API int (lua_yieldk) (lua_State *L,
int nresults, lua_KContext ctx,
312LUA_API int (lua_resume) (lua_State *L, lua_State *from,
int narg,
314LUA_API int (lua_status) (lua_State *L);
315LUA_API int (lua_isyieldable) (lua_State *L);
317#define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
323LUA_API void (lua_setwarnf) (lua_State *L, lua_WarnFunction f,
void *ud);
324LUA_API void (lua_warning) (lua_State *L,
const char *msg,
int tocont);
332#define LUA_GCRESTART 1
333#define LUA_GCCOLLECT 2
335#define LUA_GCCOUNTB 4
337#define LUA_GCISRUNNING 6
347#define LUA_GCPMINORMUL 0
348#define LUA_GCPMAJORMINOR 1
349#define LUA_GCPMINORMAJOR 2
352#define LUA_GCPPAUSE 3
353#define LUA_GCPSTEPMUL 4
354#define LUA_GCPSTEPSIZE 5
360LUA_API int (lua_gc) (lua_State *L,
int what, ...);
367LUA_API int (lua_error) (lua_State *L);
369LUA_API int (lua_next) (lua_State *L,
int idx);
371LUA_API void (lua_concat) (lua_State *L,
int n);
372LUA_API void (lua_len) (lua_State *L,
int idx);
374#define LUA_N2SBUFFSZ 64
375LUA_API unsigned (lua_numbertocstring) (lua_State *L,
int idx,
char *buff);
376LUA_API size_t (lua_stringtonumber) (lua_State *L,
const char *s);
378LUA_API lua_Alloc (lua_getallocf) (lua_State *L,
void **ud);
379LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f,
void *ud);
381LUA_API void (lua_toclose) (lua_State *L,
int idx);
382LUA_API void (lua_closeslot) (lua_State *L,
int idx);
391#define lua_getextraspace(L) ((void *)((char *)(L) - LUA_EXTRASPACE))
393#define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL)
394#define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL)
396#define lua_pop(L,n) lua_settop(L, -(n)-1)
398#define lua_newtable(L) lua_createtable(L, 0, 0)
400#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
402#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
404#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
405#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
406#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
407#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
408#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
409#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
410#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
411#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
413#define lua_pushliteral(L, s) lua_pushstring(L, "" s)
415#define lua_pushglobaltable(L) \
416 ((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS))
418#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
421#define lua_insert(L,idx) lua_rotate(L, (idx), 1)
423#define lua_remove(L,idx) (lua_rotate(L, (idx), -1), lua_pop(L, 1))
425#define lua_replace(L,idx) (lua_copy(L, -1, (idx)), lua_pop(L, 1))
436#define lua_newuserdata(L,s) lua_newuserdatauv(L,s,1)
437#define lua_getuservalue(L,idx) lua_getiuservalue(L,idx,1)
438#define lua_setuservalue(L,idx) lua_setiuservalue(L,idx,1)
440#define lua_resetthread(L) lua_closethread(L,NULL)
454#define LUA_HOOKCALL 0
456#define LUA_HOOKLINE 2
457#define LUA_HOOKCOUNT 3
458#define LUA_HOOKTAILCALL 4
464#define LUA_MASKCALL (1 << LUA_HOOKCALL)
465#define LUA_MASKRET (1 << LUA_HOOKRET)
466#define LUA_MASKLINE (1 << LUA_HOOKLINE)
467#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
470LUA_API int (lua_getstack) (lua_State *L,
int level, lua_Debug *ar);
471LUA_API int (lua_getinfo) (lua_State *L,
const char *what, lua_Debug *ar);
472LUA_API
const char *(lua_getlocal) (lua_State *L,
const lua_Debug *ar,
int n);
473LUA_API
const char *(lua_setlocal) (lua_State *L,
const lua_Debug *ar,
int n);
474LUA_API
const char *(lua_getupvalue) (lua_State *L,
int funcindex,
int n);
475LUA_API
const char *(lua_setupvalue) (lua_State *L,
int funcindex,
int n);
477LUA_API
void *(lua_upvalueid) (lua_State *L,
int fidx,
int n);
478LUA_API void (lua_upvaluejoin) (lua_State *L,
int fidx1,
int n1,
481LUA_API void (lua_sethook) (lua_State *L, lua_Hook func,
int mask,
int count);
482LUA_API lua_Hook (lua_gethook) (lua_State *L);
483LUA_API int (lua_gethookmask) (lua_State *L);
484LUA_API int (lua_gethookcount) (lua_State *L);
490 const char *namewhat;
498 unsigned char nparams;
500 unsigned char extraargs;
504 char short_src[LUA_IDSIZE];
506 struct CallInfo *i_ci;
512#define LUAI_TOSTRAUX(x) #x
513#define LUAI_TOSTR(x) LUAI_TOSTRAUX(x)
515#define LUA_VERSION_MAJOR LUAI_TOSTR(LUA_VERSION_MAJOR_N)
516#define LUA_VERSION_MINOR LUAI_TOSTR(LUA_VERSION_MINOR_N)
517#define LUA_VERSION_RELEASE LUAI_TOSTR(LUA_VERSION_RELEASE_N)
519#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
520#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE