1*bdda0531Snikita /* $NetBSD: lua.h,v 1.14 2023/06/08 21:12:08 nikita Exp $ */ 2dbec5304Smbalmer 3dbec5304Smbalmer /* 4f0dad708Snikita ** Id: lua.h 54ab4902eSlneto ** Lua - A Scripting Language 6dbec5304Smbalmer ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) 7dbec5304Smbalmer ** See Copyright Notice at the end of this file 8dbec5304Smbalmer */ 9dbec5304Smbalmer 10dbec5304Smbalmer 11dbec5304Smbalmer #ifndef lua_h 12dbec5304Smbalmer #define lua_h 13dbec5304Smbalmer 14dbec5304Smbalmer #include <stdarg.h> 1573008250Slneto #ifndef _KERNEL 16dbec5304Smbalmer #include <stddef.h> 172d6cb6c2Slneto #endif /* _KERNEL */ 18dbec5304Smbalmer 19dbec5304Smbalmer 20dbec5304Smbalmer #include "luaconf.h" 21dbec5304Smbalmer 22dbec5304Smbalmer 234ab4902eSlneto #define LUA_VERSION_MAJOR "5" 24f0dad708Snikita #define LUA_VERSION_MINOR "4" 25*bdda0531Snikita #define LUA_VERSION_RELEASE "6" 26f0dad708Snikita 27f0dad708Snikita #define LUA_VERSION_NUM 504 28*bdda0531Snikita #define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 6) 29dbec5304Smbalmer 304ab4902eSlneto #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR 314ab4902eSlneto #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE 32*bdda0531Snikita #define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2023 Lua.org, PUC-Rio" 3373008250Slneto #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes" 3473008250Slneto 35dbec5304Smbalmer 364ab4902eSlneto /* mark for precompiled code ('<esc>Lua') */ 3773008250Slneto #define LUA_SIGNATURE "\x1bLua" 38dbec5304Smbalmer 394ab4902eSlneto /* option for multiple returns in 'lua_pcall' and 'lua_call' */ 40dbec5304Smbalmer #define LUA_MULTRET (-1) 41dbec5304Smbalmer 42dbec5304Smbalmer 43dbec5304Smbalmer /* 44bee09862Smbalmer ** Pseudo-indices 45bee09862Smbalmer ** (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty 46bee09862Smbalmer ** space after that to help overflow detection) 47dbec5304Smbalmer */ 48bee09862Smbalmer #define LUA_REGISTRYINDEX (-LUAI_MAXSTACK - 1000) 494ab4902eSlneto #define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i)) 50dbec5304Smbalmer 51dbec5304Smbalmer 524ab4902eSlneto /* thread status */ 534ab4902eSlneto #define LUA_OK 0 54dbec5304Smbalmer #define LUA_YIELD 1 55dbec5304Smbalmer #define LUA_ERRRUN 2 56dbec5304Smbalmer #define LUA_ERRSYNTAX 3 57dbec5304Smbalmer #define LUA_ERRMEM 4 58f0dad708Snikita #define LUA_ERRERR 5 59dbec5304Smbalmer 60dbec5304Smbalmer 61dbec5304Smbalmer typedef struct lua_State lua_State; 62dbec5304Smbalmer 63dbec5304Smbalmer 64dbec5304Smbalmer /* 65dbec5304Smbalmer ** basic types 66dbec5304Smbalmer */ 67dbec5304Smbalmer #define LUA_TNONE (-1) 68dbec5304Smbalmer 69dbec5304Smbalmer #define LUA_TNIL 0 70dbec5304Smbalmer #define LUA_TBOOLEAN 1 71dbec5304Smbalmer #define LUA_TLIGHTUSERDATA 2 72dbec5304Smbalmer #define LUA_TNUMBER 3 73dbec5304Smbalmer #define LUA_TSTRING 4 74dbec5304Smbalmer #define LUA_TTABLE 5 75dbec5304Smbalmer #define LUA_TFUNCTION 6 76dbec5304Smbalmer #define LUA_TUSERDATA 7 77dbec5304Smbalmer #define LUA_TTHREAD 8 78dbec5304Smbalmer 79f0dad708Snikita #define LUA_NUMTYPES 9 804ab4902eSlneto 81dbec5304Smbalmer 82dbec5304Smbalmer 83dbec5304Smbalmer /* minimum Lua stack available to a C function */ 84dbec5304Smbalmer #define LUA_MINSTACK 20 85dbec5304Smbalmer 86dbec5304Smbalmer 874ab4902eSlneto /* predefined values in the registry */ 884ab4902eSlneto #define LUA_RIDX_MAINTHREAD 1 894ab4902eSlneto #define LUA_RIDX_GLOBALS 2 904ab4902eSlneto #define LUA_RIDX_LAST LUA_RIDX_GLOBALS 914ab4902eSlneto 924ab4902eSlneto 934ab4902eSlneto /* type of numbers in Lua */ 944ab4902eSlneto typedef LUA_NUMBER lua_Number; 954ab4902eSlneto 964ab4902eSlneto 974ab4902eSlneto /* type for integer functions */ 984ab4902eSlneto typedef LUA_INTEGER lua_Integer; 994ab4902eSlneto 1004ab4902eSlneto /* unsigned integer type */ 1014ab4902eSlneto typedef LUA_UNSIGNED lua_Unsigned; 1024ab4902eSlneto 10373008250Slneto /* type for continuation-function contexts */ 10473008250Slneto typedef LUA_KCONTEXT lua_KContext; 10573008250Slneto 10673008250Slneto 10773008250Slneto /* 10873008250Slneto ** Type for C functions registered with Lua 10973008250Slneto */ 11073008250Slneto typedef int (*lua_CFunction) (lua_State *L); 11173008250Slneto 11273008250Slneto /* 11373008250Slneto ** Type for continuation functions 11473008250Slneto */ 11573008250Slneto typedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx); 11673008250Slneto 11773008250Slneto 11873008250Slneto /* 11973008250Slneto ** Type for functions that read/write blocks when loading/dumping Lua chunks 12073008250Slneto */ 12173008250Slneto typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); 12273008250Slneto 12373008250Slneto typedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud); 12473008250Slneto 12573008250Slneto 12673008250Slneto /* 12773008250Slneto ** Type for memory-allocation functions 12873008250Slneto */ 12973008250Slneto typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); 13073008250Slneto 1314ab4902eSlneto 132f0dad708Snikita /* 133f0dad708Snikita ** Type for warning functions 134f0dad708Snikita */ 135f0dad708Snikita typedef void (*lua_WarnFunction) (void *ud, const char *msg, int tocont); 136f0dad708Snikita 137f0dad708Snikita 138*bdda0531Snikita /* 139*bdda0531Snikita ** Type used by the debug API to collect debug information 140*bdda0531Snikita */ 141*bdda0531Snikita typedef struct lua_Debug lua_Debug; 142*bdda0531Snikita 143*bdda0531Snikita 144*bdda0531Snikita /* 145*bdda0531Snikita ** Functions to be called by the debugger in specific events 146*bdda0531Snikita */ 147*bdda0531Snikita typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); 148f0dad708Snikita 1494ab4902eSlneto 150dbec5304Smbalmer /* 151dbec5304Smbalmer ** generic extra include file 152dbec5304Smbalmer */ 153dbec5304Smbalmer #if defined(LUA_USER_H) 154dbec5304Smbalmer #include LUA_USER_H 155dbec5304Smbalmer #endif 156dbec5304Smbalmer 157dbec5304Smbalmer 1584ab4902eSlneto /* 1594ab4902eSlneto ** RCS ident string 1604ab4902eSlneto */ 1614ab4902eSlneto extern const char lua_ident[]; 162dbec5304Smbalmer 163dbec5304Smbalmer 164dbec5304Smbalmer /* 165dbec5304Smbalmer ** state manipulation 166dbec5304Smbalmer */ 167dbec5304Smbalmer LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud); 168dbec5304Smbalmer LUA_API void (lua_close) (lua_State *L); 169dbec5304Smbalmer LUA_API lua_State *(lua_newthread) (lua_State *L); 170*bdda0531Snikita LUA_API int (lua_closethread) (lua_State *L, lua_State *from); 171*bdda0531Snikita LUA_API int (lua_resetthread) (lua_State *L); /* Deprecated! */ 172dbec5304Smbalmer 173dbec5304Smbalmer LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); 174dbec5304Smbalmer 175dbec5304Smbalmer 176f0dad708Snikita LUA_API lua_Number (lua_version) (lua_State *L); 1774ab4902eSlneto 1784ab4902eSlneto 179dbec5304Smbalmer /* 180dbec5304Smbalmer ** basic stack manipulation 181dbec5304Smbalmer */ 1824ab4902eSlneto LUA_API int (lua_absindex) (lua_State *L, int idx); 183dbec5304Smbalmer LUA_API int (lua_gettop) (lua_State *L); 184dbec5304Smbalmer LUA_API void (lua_settop) (lua_State *L, int idx); 185dbec5304Smbalmer LUA_API void (lua_pushvalue) (lua_State *L, int idx); 1864ab4902eSlneto LUA_API void (lua_rotate) (lua_State *L, int idx, int n); 1874ab4902eSlneto LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx); 18873008250Slneto LUA_API int (lua_checkstack) (lua_State *L, int n); 189dbec5304Smbalmer 190dbec5304Smbalmer LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n); 191dbec5304Smbalmer 192dbec5304Smbalmer 193dbec5304Smbalmer /* 194dbec5304Smbalmer ** access functions (stack -> C) 195dbec5304Smbalmer */ 196dbec5304Smbalmer 197dbec5304Smbalmer LUA_API int (lua_isnumber) (lua_State *L, int idx); 198dbec5304Smbalmer LUA_API int (lua_isstring) (lua_State *L, int idx); 199dbec5304Smbalmer LUA_API int (lua_iscfunction) (lua_State *L, int idx); 2004ab4902eSlneto LUA_API int (lua_isinteger) (lua_State *L, int idx); 201dbec5304Smbalmer LUA_API int (lua_isuserdata) (lua_State *L, int idx); 202dbec5304Smbalmer LUA_API int (lua_type) (lua_State *L, int idx); 203dbec5304Smbalmer LUA_API const char *(lua_typename) (lua_State *L, int tp); 204dbec5304Smbalmer 20573008250Slneto #ifndef _KERNEL 2064ab4902eSlneto LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum); 20773008250Slneto #else /* _KERNEL */ 20873008250Slneto #define lua_tonumberx (lua_Integer) lua_tointegerx 2092d6cb6c2Slneto #endif /* _KERNEL */ 2104ab4902eSlneto LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum); 211dbec5304Smbalmer LUA_API int (lua_toboolean) (lua_State *L, int idx); 212dbec5304Smbalmer LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); 213f0dad708Snikita LUA_API lua_Unsigned (lua_rawlen) (lua_State *L, int idx); 214dbec5304Smbalmer LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); 215dbec5304Smbalmer LUA_API void *(lua_touserdata) (lua_State *L, int idx); 216dbec5304Smbalmer LUA_API lua_State *(lua_tothread) (lua_State *L, int idx); 217dbec5304Smbalmer LUA_API const void *(lua_topointer) (lua_State *L, int idx); 218dbec5304Smbalmer 219dbec5304Smbalmer 220dbec5304Smbalmer /* 2214ab4902eSlneto ** Comparison and arithmetic functions 2224ab4902eSlneto */ 2234ab4902eSlneto 2244ab4902eSlneto #define LUA_OPADD 0 /* ORDER TM, ORDER OP */ 2254ab4902eSlneto #define LUA_OPSUB 1 2264ab4902eSlneto #define LUA_OPMUL 2 2274ab4902eSlneto #define LUA_OPMOD 3 2284ab4902eSlneto #ifndef _KERNEL 2294ab4902eSlneto #define LUA_OPPOW 4 2304ab4902eSlneto #define LUA_OPDIV 5 2314ab4902eSlneto #define LUA_OPIDIV 6 2324ab4902eSlneto #define LUA_OPBAND 7 2334ab4902eSlneto #define LUA_OPBOR 8 2344ab4902eSlneto #define LUA_OPBXOR 9 2354ab4902eSlneto #define LUA_OPSHL 10 2364ab4902eSlneto #define LUA_OPSHR 11 2374ab4902eSlneto #define LUA_OPUNM 12 2384ab4902eSlneto #define LUA_OPBNOT 13 23973008250Slneto #else /* _KERNEL */ 2404ab4902eSlneto #define LUA_OPIDIV 4 2414ab4902eSlneto #define LUA_OPBAND 5 2424ab4902eSlneto #define LUA_OPBOR 6 2434ab4902eSlneto #define LUA_OPBXOR 7 2444ab4902eSlneto #define LUA_OPSHL 8 2454ab4902eSlneto #define LUA_OPSHR 9 2464ab4902eSlneto #define LUA_OPUNM 10 2474ab4902eSlneto #define LUA_OPBNOT 11 2482d6cb6c2Slneto #endif /* _KERNEL */ 2494ab4902eSlneto 2504ab4902eSlneto LUA_API void (lua_arith) (lua_State *L, int op); 2514ab4902eSlneto 2524ab4902eSlneto #define LUA_OPEQ 0 2534ab4902eSlneto #define LUA_OPLT 1 2544ab4902eSlneto #define LUA_OPLE 2 2554ab4902eSlneto 2564ab4902eSlneto LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2); 2574ab4902eSlneto LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op); 2584ab4902eSlneto 2594ab4902eSlneto 2604ab4902eSlneto /* 261dbec5304Smbalmer ** push functions (C -> stack) 262dbec5304Smbalmer */ 263dbec5304Smbalmer LUA_API void (lua_pushnil) (lua_State *L); 26473008250Slneto #ifndef _KERNEL 265dbec5304Smbalmer LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); 26673008250Slneto #else /* _KERNEL */ 26773008250Slneto #define lua_pushnumber(L, n) lua_pushinteger(L, (lua_Integer)(n)) 2682d6cb6c2Slneto #endif /* _KERNEL */ 269dbec5304Smbalmer LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); 27073008250Slneto LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t len); 2714ab4902eSlneto LUA_API const char *(lua_pushstring) (lua_State *L, const char *s); 272dbec5304Smbalmer LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, 273dbec5304Smbalmer va_list argp); 274dbec5304Smbalmer LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); 275dbec5304Smbalmer LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n); 276dbec5304Smbalmer LUA_API void (lua_pushboolean) (lua_State *L, int b); 277dbec5304Smbalmer LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p); 278dbec5304Smbalmer LUA_API int (lua_pushthread) (lua_State *L); 279dbec5304Smbalmer 280dbec5304Smbalmer 281dbec5304Smbalmer /* 282dbec5304Smbalmer ** get functions (Lua -> stack) 283dbec5304Smbalmer */ 28473008250Slneto LUA_API int (lua_getglobal) (lua_State *L, const char *name); 2854ab4902eSlneto LUA_API int (lua_gettable) (lua_State *L, int idx); 2864ab4902eSlneto LUA_API int (lua_getfield) (lua_State *L, int idx, const char *k); 28773008250Slneto LUA_API int (lua_geti) (lua_State *L, int idx, lua_Integer n); 2884ab4902eSlneto LUA_API int (lua_rawget) (lua_State *L, int idx); 2894ab4902eSlneto LUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n); 2904ab4902eSlneto LUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p); 2914ab4902eSlneto 292dbec5304Smbalmer LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); 293f0dad708Snikita LUA_API void *(lua_newuserdatauv) (lua_State *L, size_t sz, int nuvalue); 294dbec5304Smbalmer LUA_API int (lua_getmetatable) (lua_State *L, int objindex); 295f0dad708Snikita LUA_API int (lua_getiuservalue) (lua_State *L, int idx, int n); 296dbec5304Smbalmer 297dbec5304Smbalmer 298dbec5304Smbalmer /* 299dbec5304Smbalmer ** set functions (stack -> Lua) 300dbec5304Smbalmer */ 30173008250Slneto LUA_API void (lua_setglobal) (lua_State *L, const char *name); 302dbec5304Smbalmer LUA_API void (lua_settable) (lua_State *L, int idx); 303dbec5304Smbalmer LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); 30473008250Slneto LUA_API void (lua_seti) (lua_State *L, int idx, lua_Integer n); 305dbec5304Smbalmer LUA_API void (lua_rawset) (lua_State *L, int idx); 3064ab4902eSlneto LUA_API void (lua_rawseti) (lua_State *L, int idx, lua_Integer n); 3074ab4902eSlneto LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p); 308dbec5304Smbalmer LUA_API int (lua_setmetatable) (lua_State *L, int objindex); 309f0dad708Snikita LUA_API int (lua_setiuservalue) (lua_State *L, int idx, int n); 310dbec5304Smbalmer 311dbec5304Smbalmer 312dbec5304Smbalmer /* 3134ab4902eSlneto ** 'load' and 'call' functions (load and run Lua code) 314dbec5304Smbalmer */ 31573008250Slneto LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults, 31673008250Slneto lua_KContext ctx, lua_KFunction k); 3174ab4902eSlneto #define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL) 318dbec5304Smbalmer 3194ab4902eSlneto LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc, 32073008250Slneto lua_KContext ctx, lua_KFunction k); 3214ab4902eSlneto #define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL) 3224ab4902eSlneto 3234ab4902eSlneto LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, 32473008250Slneto const char *chunkname, const char *mode); 3254ab4902eSlneto 3264ab4902eSlneto LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip); 327dbec5304Smbalmer 328dbec5304Smbalmer 329dbec5304Smbalmer /* 330dbec5304Smbalmer ** coroutine functions 331dbec5304Smbalmer */ 33273008250Slneto LUA_API int (lua_yieldk) (lua_State *L, int nresults, lua_KContext ctx, 3334ab4902eSlneto lua_KFunction k); 334f0dad708Snikita LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg, 335f0dad708Snikita int *nres); 336dbec5304Smbalmer LUA_API int (lua_status) (lua_State *L); 33773008250Slneto LUA_API int (lua_isyieldable) (lua_State *L); 33873008250Slneto 33973008250Slneto #define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL) 3404ab4902eSlneto 341dbec5304Smbalmer 342dbec5304Smbalmer /* 343f0dad708Snikita ** Warning-related functions 344f0dad708Snikita */ 345f0dad708Snikita LUA_API void (lua_setwarnf) (lua_State *L, lua_WarnFunction f, void *ud); 346f0dad708Snikita LUA_API void (lua_warning) (lua_State *L, const char *msg, int tocont); 347f0dad708Snikita 348f0dad708Snikita 349f0dad708Snikita /* 350dbec5304Smbalmer ** garbage-collection function and options 351dbec5304Smbalmer */ 352dbec5304Smbalmer 353dbec5304Smbalmer #define LUA_GCSTOP 0 354dbec5304Smbalmer #define LUA_GCRESTART 1 355dbec5304Smbalmer #define LUA_GCCOLLECT 2 356dbec5304Smbalmer #define LUA_GCCOUNT 3 357dbec5304Smbalmer #define LUA_GCCOUNTB 4 358dbec5304Smbalmer #define LUA_GCSTEP 5 359dbec5304Smbalmer #define LUA_GCSETPAUSE 6 360dbec5304Smbalmer #define LUA_GCSETSTEPMUL 7 3614ab4902eSlneto #define LUA_GCISRUNNING 9 362f0dad708Snikita #define LUA_GCGEN 10 363f0dad708Snikita #define LUA_GCINC 11 364dbec5304Smbalmer 365f0dad708Snikita LUA_API int (lua_gc) (lua_State *L, int what, ...); 366dbec5304Smbalmer 367dbec5304Smbalmer 368dbec5304Smbalmer /* 369dbec5304Smbalmer ** miscellaneous functions 370dbec5304Smbalmer */ 371dbec5304Smbalmer 372dbec5304Smbalmer LUA_API int (lua_error) (lua_State *L); 373dbec5304Smbalmer 374dbec5304Smbalmer LUA_API int (lua_next) (lua_State *L, int idx); 375dbec5304Smbalmer 376dbec5304Smbalmer LUA_API void (lua_concat) (lua_State *L, int n); 3774ab4902eSlneto LUA_API void (lua_len) (lua_State *L, int idx); 3784ab4902eSlneto 37973008250Slneto LUA_API size_t (lua_stringtonumber) (lua_State *L, const char *s); 380dbec5304Smbalmer 381dbec5304Smbalmer LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); 3824ab4902eSlneto LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud); 383dbec5304Smbalmer 384f0dad708Snikita LUA_API void (lua_toclose) (lua_State *L, int idx); 385f0dad708Snikita LUA_API void (lua_closeslot) (lua_State *L, int idx); 386dbec5304Smbalmer 387dbec5304Smbalmer 388dbec5304Smbalmer /* 38973008250Slneto ** {============================================================== 390dbec5304Smbalmer ** some useful macros 391dbec5304Smbalmer ** =============================================================== 392dbec5304Smbalmer */ 393dbec5304Smbalmer 39473008250Slneto #define lua_getextraspace(L) ((void *)((char *)(L) - LUA_EXTRASPACE)) 39573008250Slneto 3964ab4902eSlneto #define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL) 3974ab4902eSlneto #define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL) 3984ab4902eSlneto 399dbec5304Smbalmer #define lua_pop(L,n) lua_settop(L, -(n)-1) 400dbec5304Smbalmer 401dbec5304Smbalmer #define lua_newtable(L) lua_createtable(L, 0, 0) 402dbec5304Smbalmer 403dbec5304Smbalmer #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) 404dbec5304Smbalmer 405dbec5304Smbalmer #define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) 406dbec5304Smbalmer 407dbec5304Smbalmer #define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) 408dbec5304Smbalmer #define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) 409dbec5304Smbalmer #define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) 410dbec5304Smbalmer #define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) 411dbec5304Smbalmer #define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) 412dbec5304Smbalmer #define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) 413dbec5304Smbalmer #define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) 414dbec5304Smbalmer #define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) 415dbec5304Smbalmer 416bee09862Smbalmer #define lua_pushliteral(L, s) lua_pushstring(L, "" s) 417dbec5304Smbalmer 4184ab4902eSlneto #define lua_pushglobaltable(L) \ 419c7f896d7Ssalazar ((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)) 420dbec5304Smbalmer 421dbec5304Smbalmer #define lua_tostring(L,i) lua_tolstring(L, (i), NULL) 422dbec5304Smbalmer 423dbec5304Smbalmer 4244ab4902eSlneto #define lua_insert(L,idx) lua_rotate(L, (idx), 1) 425dbec5304Smbalmer 4264ab4902eSlneto #define lua_remove(L,idx) (lua_rotate(L, (idx), -1), lua_pop(L, 1)) 427dbec5304Smbalmer 42873008250Slneto #define lua_replace(L,idx) (lua_copy(L, -1, (idx)), lua_pop(L, 1)) 42973008250Slneto 43073008250Slneto /* }============================================================== */ 43173008250Slneto 43273008250Slneto 43373008250Slneto /* 43473008250Slneto ** {============================================================== 435f0dad708Snikita ** compatibility macros 43673008250Slneto ** =============================================================== 43773008250Slneto */ 43873008250Slneto #if defined(LUA_COMPAT_APIINTCASTS) 43973008250Slneto 44073008250Slneto #define lua_pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n)) 44173008250Slneto #define lua_tounsignedx(L,i,is) ((lua_Unsigned)lua_tointegerx(L,i,is)) 44273008250Slneto #define lua_tounsigned(L,i) lua_tounsignedx(L,(i),NULL) 44373008250Slneto 44473008250Slneto #endif 445f0dad708Snikita 446f0dad708Snikita #define lua_newuserdata(L,s) lua_newuserdatauv(L,s,1) 447f0dad708Snikita #define lua_getuservalue(L,idx) lua_getiuservalue(L,idx,1) 448f0dad708Snikita #define lua_setuservalue(L,idx) lua_setiuservalue(L,idx,1) 449f0dad708Snikita 450f0dad708Snikita #define LUA_NUMTAGS LUA_NUMTYPES 451f0dad708Snikita 45273008250Slneto /* }============================================================== */ 453dbec5304Smbalmer 454dbec5304Smbalmer /* 455dbec5304Smbalmer ** {====================================================================== 456dbec5304Smbalmer ** Debug API 457dbec5304Smbalmer ** ======================================================================= 458dbec5304Smbalmer */ 459dbec5304Smbalmer 460dbec5304Smbalmer 461dbec5304Smbalmer /* 462dbec5304Smbalmer ** Event codes 463dbec5304Smbalmer */ 464dbec5304Smbalmer #define LUA_HOOKCALL 0 465dbec5304Smbalmer #define LUA_HOOKRET 1 466dbec5304Smbalmer #define LUA_HOOKLINE 2 467dbec5304Smbalmer #define LUA_HOOKCOUNT 3 4684ab4902eSlneto #define LUA_HOOKTAILCALL 4 469dbec5304Smbalmer 470dbec5304Smbalmer 471dbec5304Smbalmer /* 472dbec5304Smbalmer ** Event masks 473dbec5304Smbalmer */ 474dbec5304Smbalmer #define LUA_MASKCALL (1 << LUA_HOOKCALL) 475dbec5304Smbalmer #define LUA_MASKRET (1 << LUA_HOOKRET) 476dbec5304Smbalmer #define LUA_MASKLINE (1 << LUA_HOOKLINE) 477dbec5304Smbalmer #define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) 478dbec5304Smbalmer 479dbec5304Smbalmer 4804ab4902eSlneto LUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar); 4814ab4902eSlneto LUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar); 4824ab4902eSlneto LUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n); 4834ab4902eSlneto LUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n); 4844ab4902eSlneto LUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n); 4854ab4902eSlneto LUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n); 486dbec5304Smbalmer 4874ab4902eSlneto LUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n); 4884ab4902eSlneto LUA_API void (lua_upvaluejoin) (lua_State *L, int fidx1, int n1, 4894ab4902eSlneto int fidx2, int n2); 4904ab4902eSlneto 4914ab4902eSlneto LUA_API void (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count); 4924ab4902eSlneto LUA_API lua_Hook (lua_gethook) (lua_State *L); 4934ab4902eSlneto LUA_API int (lua_gethookmask) (lua_State *L); 4944ab4902eSlneto LUA_API int (lua_gethookcount) (lua_State *L); 495dbec5304Smbalmer 496f0dad708Snikita LUA_API int (lua_setcstacklimit) (lua_State *L, unsigned int limit); 497dbec5304Smbalmer 498dbec5304Smbalmer struct lua_Debug { 499dbec5304Smbalmer int event; 500dbec5304Smbalmer const char *name; /* (n) */ 5014ab4902eSlneto const char *namewhat; /* (n) 'global', 'local', 'field', 'method' */ 5024ab4902eSlneto const char *what; /* (S) 'Lua', 'C', 'main', 'tail' */ 503dbec5304Smbalmer const char *source; /* (S) */ 504f0dad708Snikita size_t srclen; /* (S) */ 505dbec5304Smbalmer int currentline; /* (l) */ 506dbec5304Smbalmer int linedefined; /* (S) */ 507dbec5304Smbalmer int lastlinedefined; /* (S) */ 5084ab4902eSlneto unsigned char nups; /* (u) number of upvalues */ 5094ab4902eSlneto unsigned char nparams;/* (u) number of parameters */ 5104ab4902eSlneto char isvararg; /* (u) */ 5114ab4902eSlneto char istailcall; /* (t) */ 512f0dad708Snikita unsigned short ftransfer; /* (r) index of first value transferred */ 513f0dad708Snikita unsigned short ntransfer; /* (r) number of transferred values */ 514dbec5304Smbalmer char short_src[LUA_IDSIZE]; /* (S) */ 515dbec5304Smbalmer /* private part */ 5164ab4902eSlneto struct CallInfo *i_ci; /* active function */ 517dbec5304Smbalmer }; 518dbec5304Smbalmer 519dbec5304Smbalmer /* }====================================================================== */ 520dbec5304Smbalmer 521dbec5304Smbalmer 522dbec5304Smbalmer /****************************************************************************** 52373008250Slneto #ifdef _KERNEL 5249e2f6347Smbalmer * Copyright (c) 2016-2017, Lourival Vieira Neto <lneto@NetBSD.org>. 52573008250Slneto #endif 526*bdda0531Snikita * Copyright (C) 1994-2023 Lua.org, PUC-Rio. 527dbec5304Smbalmer * 528dbec5304Smbalmer * Permission is hereby granted, free of charge, to any person obtaining 529dbec5304Smbalmer * a copy of this software and associated documentation files (the 530dbec5304Smbalmer * "Software"), to deal in the Software without restriction, including 531dbec5304Smbalmer * without limitation the rights to use, copy, modify, merge, publish, 532dbec5304Smbalmer * distribute, sublicense, and/or sell copies of the Software, and to 533dbec5304Smbalmer * permit persons to whom the Software is furnished to do so, subject to 534dbec5304Smbalmer * the following conditions: 535dbec5304Smbalmer * 536dbec5304Smbalmer * The above copyright notice and this permission notice shall be 537dbec5304Smbalmer * included in all copies or substantial portions of the Software. 538dbec5304Smbalmer * 539dbec5304Smbalmer * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 540dbec5304Smbalmer * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 541dbec5304Smbalmer * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 542dbec5304Smbalmer * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 543dbec5304Smbalmer * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 544dbec5304Smbalmer * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 545dbec5304Smbalmer * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 546dbec5304Smbalmer ******************************************************************************/ 547dbec5304Smbalmer 548dbec5304Smbalmer 549dbec5304Smbalmer #endif 550