sdk-world v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Loading...
Searching...
No Matches
lua.h
Go to the documentation of this file.
1/*
2** $Id: lua.h $
3** Lua - A Scripting Language
4** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
5** See Copyright Notice at the end of this file
6*/
7
8
13#ifndef lua_h
14#define lua_h
15
16#include <stdarg.h>
17#include <stddef.h>
18
19
20#include "luaconf.h"
21
22
23#define LUA_VERSION_MAJOR "5"
24#define LUA_VERSION_MINOR "4"
25#define LUA_VERSION_RELEASE "6"
26
27#define LUA_VERSION_NUM 504
28#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 6)
29
30#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
31#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
32#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2023 Lua.org, PUC-Rio"
33#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
34
35
36/* mark for precompiled code ('<esc>Lua') */
37#define LUA_SIGNATURE "\x1bLua"
38
39/* option for multiple returns in 'lua_pcall' and 'lua_call' */
40#define LUA_MULTRET (-1)
41
42
43/*
44** Pseudo-indices
45** (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty
46** space after that to help overflow detection)
47*/
48#define LUA_REGISTRYINDEX (-LUAI_MAXSTACK - 1000)
49#define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i))
50
51
52/* thread status */
53#define LUA_OK 0
54#define LUA_YIELD 1
55#define LUA_ERRRUN 2
56#define LUA_ERRSYNTAX 3
57#define LUA_ERRMEM 4
58#define LUA_ERRERR 5
59
60
61typedef struct lua_State lua_State;
62
63
64/*
65** basic types
66*/
67#define LUA_TNONE (-1)
68
69#define LUA_TNIL 0
70#define LUA_TBOOLEAN 1
71#define LUA_TLIGHTUSERDATA 2
72#define LUA_TNUMBER 3
73#define LUA_TSTRING 4
74#define LUA_TTABLE 5
75#define LUA_TFUNCTION 6
76#define LUA_TUSERDATA 7
77#define LUA_TTHREAD 8
78
79#define LUA_NUMTYPES 9
80
81
82
83/* minimum Lua stack available to a C function */
84#define LUA_MINSTACK 20
85
86
87/* predefined values in the registry */
88#define LUA_RIDX_MAINTHREAD 1
89#define LUA_RIDX_GLOBALS 2
90#define LUA_RIDX_LAST LUA_RIDX_GLOBALS
91
92
93/* type of numbers in Lua */
94typedef LUA_NUMBER lua_Number;
95
96
97/* type for integer functions */
98typedef LUA_INTEGER lua_Integer;
99
100/* unsigned integer type */
101typedef LUA_UNSIGNED lua_Unsigned;
102
103/* type for continuation-function contexts */
104typedef LUA_KCONTEXT lua_KContext;
105
106
107/*
108** Type for C functions registered with Lua
109*/
110typedef int (*lua_CFunction) (lua_State *L);
111
112/*
113** Type for continuation functions
114*/
115typedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx);
116
117
118/*
119** Type for functions that read/write blocks when loading/dumping Lua chunks
120*/
121typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
122
123typedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud);
124
125
126/*
127** Type for memory-allocation functions
128*/
129typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
130
131
132/*
133** Type for warning functions
134*/
135typedef void (*lua_WarnFunction) (void *ud, const char *msg, int tocont);
136
137
138/*
139** Type used by the debug API to collect debug information
140*/
141typedef struct lua_Debug lua_Debug;
142
143
144/*
145** Functions to be called by the debugger in specific events
146*/
147typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
148
149
150/*
151** generic extra include file
152*/
153#if defined(LUA_USER_H)
154#include LUA_USER_H
155#endif
156
157
158/*
159** RCS ident string
160*/
161extern const char lua_ident[];
162
163
164/*
165** state manipulation
166*/
167LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
168LUA_API void (lua_close) (lua_State *L);
169LUA_API lua_State *(lua_newthread) (lua_State *L);
170LUA_API int (lua_closethread) (lua_State *L, lua_State *from);
171LUA_API int (lua_resetthread) (lua_State *L); /* Deprecated! */
172
173LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
174
175
176LUA_API lua_Number (lua_version) (lua_State *L);
177
178
179/*
180** basic stack manipulation
181*/
182LUA_API int (lua_absindex) (lua_State *L, int idx);
183LUA_API int (lua_gettop) (lua_State *L);
184LUA_API void (lua_settop) (lua_State *L, int idx);
185LUA_API void (lua_pushvalue) (lua_State *L, int idx);
186LUA_API void (lua_rotate) (lua_State *L, int idx, int n);
187LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx);
188LUA_API int (lua_checkstack) (lua_State *L, int n);
189
190LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
191
192
193/*
194** access functions (stack -> C)
195*/
196
197LUA_API int (lua_isnumber) (lua_State *L, int idx);
198LUA_API int (lua_isstring) (lua_State *L, int idx);
199LUA_API int (lua_iscfunction) (lua_State *L, int idx);
200LUA_API int (lua_isinteger) (lua_State *L, int idx);
201LUA_API int (lua_isuserdata) (lua_State *L, int idx);
202LUA_API int (lua_type) (lua_State *L, int idx);
203LUA_API const char *(lua_typename) (lua_State *L, int tp);
204
205LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
206LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);
207LUA_API int (lua_toboolean) (lua_State *L, int idx);
208LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
209LUA_API lua_Unsigned (lua_rawlen) (lua_State *L, int idx);
210LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
211LUA_API void *(lua_touserdata) (lua_State *L, int idx);
212LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
213LUA_API const void *(lua_topointer) (lua_State *L, int idx);
214
215
216/*
217** Comparison and arithmetic functions
218*/
219
220#define LUA_OPADD 0 /* ORDER TM, ORDER OP */
221#define LUA_OPSUB 1
222#define LUA_OPMUL 2
223#define LUA_OPMOD 3
224#define LUA_OPPOW 4
225#define LUA_OPDIV 5
226#define LUA_OPIDIV 6
227#define LUA_OPBAND 7
228#define LUA_OPBOR 8
229#define LUA_OPBXOR 9
230#define LUA_OPSHL 10
231#define LUA_OPSHR 11
232#define LUA_OPUNM 12
233#define LUA_OPBNOT 13
234
235LUA_API void (lua_arith) (lua_State *L, int op);
236
237#define LUA_OPEQ 0
238#define LUA_OPLT 1
239#define LUA_OPLE 2
240
241LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
242LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op);
243
244
245/*
246** push functions (C -> stack)
247*/
248LUA_API void (lua_pushnil) (lua_State *L);
249LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
250LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
251LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t len);
252LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
253LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
254 va_list argp);
255LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
256LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
257LUA_API void (lua_pushboolean) (lua_State *L, int b);
258LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
259LUA_API int (lua_pushthread) (lua_State *L);
260
261
262/*
263** get functions (Lua -> stack)
264*/
265LUA_API int (lua_getglobal) (lua_State *L, const char *name);
266LUA_API int (lua_gettable) (lua_State *L, int idx);
267LUA_API int (lua_getfield) (lua_State *L, int idx, const char *k);
268LUA_API int (lua_geti) (lua_State *L, int idx, lua_Integer n);
269LUA_API int (lua_rawget) (lua_State *L, int idx);
270LUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n);
271LUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p);
272
273LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
274LUA_API void *(lua_newuserdatauv) (lua_State *L, size_t sz, int nuvalue);
275LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
276LUA_API int (lua_getiuservalue) (lua_State *L, int idx, int n);
277
278
279/*
280** set functions (stack -> Lua)
281*/
282LUA_API void (lua_setglobal) (lua_State *L, const char *name);
283LUA_API void (lua_settable) (lua_State *L, int idx);
284LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
285LUA_API void (lua_seti) (lua_State *L, int idx, lua_Integer n);
286LUA_API void (lua_rawset) (lua_State *L, int idx);
287LUA_API void (lua_rawseti) (lua_State *L, int idx, lua_Integer n);
288LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p);
289LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
290LUA_API int (lua_setiuservalue) (lua_State *L, int idx, int n);
291
292
293/*
294** 'load' and 'call' functions (load and run Lua code)
295*/
296LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults,
297 lua_KContext ctx, lua_KFunction k);
298#define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL)
299
300LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
301 lua_KContext ctx, lua_KFunction k);
302#define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL)
303
304LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
305 const char *chunkname, const char *mode);
306
307LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip);
308
309
310/*
311** coroutine functions
312*/
313LUA_API int (lua_yieldk) (lua_State *L, int nresults, lua_KContext ctx,
314 lua_KFunction k);
315LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg,
316 int *nres);
317LUA_API int (lua_status) (lua_State *L);
318LUA_API int (lua_isyieldable) (lua_State *L);
319
320#define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
321
322
323/*
324** Warning-related functions
325*/
326LUA_API void (lua_setwarnf) (lua_State *L, lua_WarnFunction f, void *ud);
327LUA_API void (lua_warning) (lua_State *L, const char *msg, int tocont);
328
329
330/*
331** garbage-collection function and options
332*/
333
334#define LUA_GCSTOP 0
335#define LUA_GCRESTART 1
336#define LUA_GCCOLLECT 2
337#define LUA_GCCOUNT 3
338#define LUA_GCCOUNTB 4
339#define LUA_GCSTEP 5
340#define LUA_GCSETPAUSE 6
341#define LUA_GCSETSTEPMUL 7
342#define LUA_GCISRUNNING 9
343#define LUA_GCGEN 10
344#define LUA_GCINC 11
345
346LUA_API int (lua_gc) (lua_State *L, int what, ...);
347
348
349/*
350** miscellaneous functions
351*/
352
353LUA_API int (lua_error) (lua_State *L);
354
355LUA_API int (lua_next) (lua_State *L, int idx);
356
357LUA_API void (lua_concat) (lua_State *L, int n);
358LUA_API void (lua_len) (lua_State *L, int idx);
359
360LUA_API size_t (lua_stringtonumber) (lua_State *L, const char *s);
361
362LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
363LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
364
365LUA_API void (lua_toclose) (lua_State *L, int idx);
366LUA_API void (lua_closeslot) (lua_State *L, int idx);
367
368
369/*
370** {==============================================================
371** some useful macros
372** ===============================================================
373*/
374
375#define lua_getextraspace(L) ((void *)((char *)(L) - LUA_EXTRASPACE))
376
377#define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL)
378#define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL)
379
380#define lua_pop(L,n) lua_settop(L, -(n)-1)
381
382#define lua_newtable(L) lua_createtable(L, 0, 0)
383
384#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
385
386#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
387
388#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
389#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
390#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
391#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
392#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
393#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
394#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
395#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
396
397#define lua_pushliteral(L, s) lua_pushstring(L, "" s)
398
399#define lua_pushglobaltable(L) \
400 ((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS))
401
402#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
403
404
405#define lua_insert(L,idx) lua_rotate(L, (idx), 1)
406
407#define lua_remove(L,idx) (lua_rotate(L, (idx), -1), lua_pop(L, 1))
408
409#define lua_replace(L,idx) (lua_copy(L, -1, (idx)), lua_pop(L, 1))
410
411/* }============================================================== */
412
413
414/*
415** {==============================================================
416** compatibility macros
417** ===============================================================
418*/
419#if defined(LUA_COMPAT_APIINTCASTS)
420
421#define lua_pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n))
422#define lua_tounsignedx(L,i,is) ((lua_Unsigned)lua_tointegerx(L,i,is))
423#define lua_tounsigned(L,i) lua_tounsignedx(L,(i),NULL)
424
425#endif
426
427#define lua_newuserdata(L,s) lua_newuserdatauv(L,s,1)
428#define lua_getuservalue(L,idx) lua_getiuservalue(L,idx,1)
429#define lua_setuservalue(L,idx) lua_setiuservalue(L,idx,1)
430
431#define LUA_NUMTAGS LUA_NUMTYPES
432
433/* }============================================================== */
434
435/*
436** {======================================================================
437** Debug API
438** =======================================================================
439*/
440
441
442/*
443** Event codes
444*/
445#define LUA_HOOKCALL 0
446#define LUA_HOOKRET 1
447#define LUA_HOOKLINE 2
448#define LUA_HOOKCOUNT 3
449#define LUA_HOOKTAILCALL 4
450
451
452/*
453** Event masks
454*/
455#define LUA_MASKCALL (1 << LUA_HOOKCALL)
456#define LUA_MASKRET (1 << LUA_HOOKRET)
457#define LUA_MASKLINE (1 << LUA_HOOKLINE)
458#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
459
460
461LUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);
462LUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);
463LUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n);
464LUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n);
465LUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n);
466LUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n);
467
468LUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n);
469LUA_API void (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,
470 int fidx2, int n2);
471
472LUA_API void (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);
473LUA_API lua_Hook (lua_gethook) (lua_State *L);
474LUA_API int (lua_gethookmask) (lua_State *L);
475LUA_API int (lua_gethookcount) (lua_State *L);
476
477LUA_API int (lua_setcstacklimit) (lua_State *L, unsigned int limit);
478
479struct lua_Debug {
480 int event;
481 const char *name; /* (n) */
482 const char *namewhat; /* (n) 'global', 'local', 'field', 'method' */
483 const char *what; /* (S) 'Lua', 'C', 'main', 'tail' */
484 const char *source; /* (S) */
485 size_t srclen; /* (S) */
486 int currentline; /* (l) */
487 int linedefined; /* (S) */
488 int lastlinedefined; /* (S) */
489 unsigned char nups; /* (u) number of upvalues */
490 unsigned char nparams;/* (u) number of parameters */
491 char isvararg; /* (u) */
492 char istailcall; /* (t) */
493 unsigned short ftransfer; /* (r) index of first value transferred */
494 unsigned short ntransfer; /* (r) number of transferred values */
495 char short_src[LUA_IDSIZE]; /* (S) */
496 /* private part */
497 struct CallInfo *i_ci; /* active function */
498};
499
500/* }====================================================================== */
501
502
503/******************************************************************************
504* Copyright (C) 1994-2023 Lua.org, PUC-Rio.
505*
506* Permission is hereby granted, free of charge, to any person obtaining
507* a copy of this software and associated documentation files (the
508* "Software"), to deal in the Software without restriction, including
509* without limitation the rights to use, copy, modify, merge, publish,
510* distribute, sublicense, and/or sell copies of the Software, and to
511* permit persons to whom the Software is furnished to do so, subject to
512* the following conditions:
513*
514* The above copyright notice and this permission notice shall be
515* included in all copies or substantial portions of the Software.
516*
517* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
518* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
519* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
520* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
521* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
522* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
523* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
524******************************************************************************/
525
526
527#endif