Remove building with NOCRYPTO option
[minix.git] / external / mit / lua / dist / src / lua.h
blobb80435cebb5d71b2491e4ee385180be002352eee
1 /* $NetBSD: lua.h,v 1.5 2015/10/08 13:21:00 mbalmer Exp $ */
3 /*
4 ** Id: lua.h,v 1.328 2015/06/03 13:03:38 roberto Exp
5 ** Lua - A Scripting Language
6 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
7 ** See Copyright Notice at the end of this file
8 */
11 #ifndef lua_h
12 #define lua_h
14 #include <stdarg.h>
15 #ifndef _KERNEL
16 #include <stddef.h>
17 #endif
20 #include "luaconf.h"
23 #define LUA_VERSION_MAJOR "5"
24 #define LUA_VERSION_MINOR "3"
25 #define LUA_VERSION_NUM 503
26 #ifndef _KERNEL
27 #define LUA_VERSION_RELEASE "1"
28 #else /* _KERNEL */
29 #define LUA_VERSION_RELEASE "1 (kernel)"
30 #endif
32 #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
33 #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
34 #ifndef _KERNEL
35 #define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2015 Lua.org, PUC-Rio"
36 #else /* _KERNEL */
37 #define LUA_COPYRIGHT LUA_RELEASE \
38 " Copyright (c) 2015, Lourival Vieira Neto <lneto@NetBSD.org>." \
39 " Copyright (C) 1994-2015 Lua.org, PUC-Rio"
40 #endif
41 #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
44 /* mark for precompiled code ('<esc>Lua') */
45 #define LUA_SIGNATURE "\x1bLua"
47 /* option for multiple returns in 'lua_pcall' and 'lua_call' */
48 #define LUA_MULTRET (-1)
52 ** Pseudo-indices
53 ** (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty
54 ** space after that to help overflow detection)
56 #define LUA_REGISTRYINDEX (-LUAI_MAXSTACK - 1000)
57 #define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i))
60 /* thread status */
61 #define LUA_OK 0
62 #define LUA_YIELD 1
63 #define LUA_ERRRUN 2
64 #define LUA_ERRSYNTAX 3
65 #define LUA_ERRMEM 4
66 #define LUA_ERRGCMM 5
67 #define LUA_ERRERR 6
70 typedef struct lua_State lua_State;
74 ** basic types
76 #define LUA_TNONE (-1)
78 #define LUA_TNIL 0
79 #define LUA_TBOOLEAN 1
80 #define LUA_TLIGHTUSERDATA 2
81 #define LUA_TNUMBER 3
82 #define LUA_TSTRING 4
83 #define LUA_TTABLE 5
84 #define LUA_TFUNCTION 6
85 #define LUA_TUSERDATA 7
86 #define LUA_TTHREAD 8
88 #define LUA_NUMTAGS 9
92 /* minimum Lua stack available to a C function */
93 #define LUA_MINSTACK 20
96 /* predefined values in the registry */
97 #define LUA_RIDX_MAINTHREAD 1
98 #define LUA_RIDX_GLOBALS 2
99 #define LUA_RIDX_LAST LUA_RIDX_GLOBALS
102 /* type of numbers in Lua */
103 typedef LUA_NUMBER lua_Number;
106 /* type for integer functions */
107 typedef LUA_INTEGER lua_Integer;
109 /* unsigned integer type */
110 typedef LUA_UNSIGNED lua_Unsigned;
112 /* type for continuation-function contexts */
113 typedef LUA_KCONTEXT lua_KContext;
117 ** Type for C functions registered with Lua
119 typedef int (*lua_CFunction) (lua_State *L);
122 ** Type for continuation functions
124 typedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx);
128 ** Type for functions that read/write blocks when loading/dumping Lua chunks
130 typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
132 typedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud);
136 ** Type for memory-allocation functions
138 typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
143 ** generic extra include file
145 #if defined(LUA_USER_H)
146 #include LUA_USER_H
147 #endif
151 ** RCS ident string
153 extern const char lua_ident[];
157 ** state manipulation
159 LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
160 LUA_API void (lua_close) (lua_State *L);
161 LUA_API lua_State *(lua_newthread) (lua_State *L);
163 LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
166 LUA_API const lua_Number *(lua_version) (lua_State *L);
170 ** basic stack manipulation
172 LUA_API int (lua_absindex) (lua_State *L, int idx);
173 LUA_API int (lua_gettop) (lua_State *L);
174 LUA_API void (lua_settop) (lua_State *L, int idx);
175 LUA_API void (lua_pushvalue) (lua_State *L, int idx);
176 LUA_API void (lua_rotate) (lua_State *L, int idx, int n);
177 LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx);
178 LUA_API int (lua_checkstack) (lua_State *L, int n);
180 LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
184 ** access functions (stack -> C)
187 LUA_API int (lua_isnumber) (lua_State *L, int idx);
188 LUA_API int (lua_isstring) (lua_State *L, int idx);
189 LUA_API int (lua_iscfunction) (lua_State *L, int idx);
190 LUA_API int (lua_isinteger) (lua_State *L, int idx);
191 LUA_API int (lua_isuserdata) (lua_State *L, int idx);
192 LUA_API int (lua_type) (lua_State *L, int idx);
193 LUA_API const char *(lua_typename) (lua_State *L, int tp);
195 #ifndef _KERNEL
196 LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
197 #else /* _KERNEL */
198 #define lua_tonumberx (lua_Integer) lua_tointegerx
199 #endif
200 LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);
201 LUA_API int (lua_toboolean) (lua_State *L, int idx);
202 LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
203 LUA_API size_t (lua_rawlen) (lua_State *L, int idx);
204 LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
205 LUA_API void *(lua_touserdata) (lua_State *L, int idx);
206 LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
207 LUA_API const void *(lua_topointer) (lua_State *L, int idx);
211 ** Comparison and arithmetic functions
214 #define LUA_OPADD 0 /* ORDER TM, ORDER OP */
215 #define LUA_OPSUB 1
216 #define LUA_OPMUL 2
217 #define LUA_OPMOD 3
218 #ifndef _KERNEL
219 #define LUA_OPPOW 4
220 #define LUA_OPDIV 5
221 #define LUA_OPIDIV 6
222 #define LUA_OPBAND 7
223 #define LUA_OPBOR 8
224 #define LUA_OPBXOR 9
225 #define LUA_OPSHL 10
226 #define LUA_OPSHR 11
227 #define LUA_OPUNM 12
228 #define LUA_OPBNOT 13
229 #else /* _KERNEL */
230 #define LUA_OPIDIV 4
231 #define LUA_OPBAND 5
232 #define LUA_OPBOR 6
233 #define LUA_OPBXOR 7
234 #define LUA_OPSHL 8
235 #define LUA_OPSHR 9
236 #define LUA_OPUNM 10
237 #define LUA_OPBNOT 11
238 #endif
240 LUA_API void (lua_arith) (lua_State *L, int op);
242 #define LUA_OPEQ 0
243 #define LUA_OPLT 1
244 #define LUA_OPLE 2
246 LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
247 LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op);
251 ** push functions (C -> stack)
253 LUA_API void (lua_pushnil) (lua_State *L);
254 #ifndef _KERNEL
255 LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
256 #else /* _KERNEL */
257 #define lua_pushnumber(L, n) lua_pushinteger(L, (lua_Integer)(n))
258 #endif
259 LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
260 LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t len);
261 LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
262 LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
263 va_list argp);
264 LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
265 LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
266 LUA_API void (lua_pushboolean) (lua_State *L, int b);
267 LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
268 LUA_API int (lua_pushthread) (lua_State *L);
272 ** get functions (Lua -> stack)
274 LUA_API int (lua_getglobal) (lua_State *L, const char *name);
275 LUA_API int (lua_gettable) (lua_State *L, int idx);
276 LUA_API int (lua_getfield) (lua_State *L, int idx, const char *k);
277 LUA_API int (lua_geti) (lua_State *L, int idx, lua_Integer n);
278 LUA_API int (lua_rawget) (lua_State *L, int idx);
279 LUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n);
280 LUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p);
282 LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
283 LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
284 LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
285 LUA_API int (lua_getuservalue) (lua_State *L, int idx);
289 ** set functions (stack -> Lua)
291 LUA_API void (lua_setglobal) (lua_State *L, const char *name);
292 LUA_API void (lua_settable) (lua_State *L, int idx);
293 LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
294 LUA_API void (lua_seti) (lua_State *L, int idx, lua_Integer n);
295 LUA_API void (lua_rawset) (lua_State *L, int idx);
296 LUA_API void (lua_rawseti) (lua_State *L, int idx, lua_Integer n);
297 LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p);
298 LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
299 LUA_API void (lua_setuservalue) (lua_State *L, int idx);
303 ** 'load' and 'call' functions (load and run Lua code)
305 LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults,
306 lua_KContext ctx, lua_KFunction k);
307 #define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL)
309 LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
310 lua_KContext ctx, lua_KFunction k);
311 #define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL)
313 LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
314 const char *chunkname, const char *mode);
316 LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip);
320 ** coroutine functions
322 LUA_API int (lua_yieldk) (lua_State *L, int nresults, lua_KContext ctx,
323 lua_KFunction k);
324 LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg);
325 LUA_API int (lua_status) (lua_State *L);
326 LUA_API int (lua_isyieldable) (lua_State *L);
328 #define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
332 ** garbage-collection function and options
335 #define LUA_GCSTOP 0
336 #define LUA_GCRESTART 1
337 #define LUA_GCCOLLECT 2
338 #define LUA_GCCOUNT 3
339 #define LUA_GCCOUNTB 4
340 #define LUA_GCSTEP 5
341 #define LUA_GCSETPAUSE 6
342 #define LUA_GCSETSTEPMUL 7
343 #define LUA_GCISRUNNING 9
345 LUA_API int (lua_gc) (lua_State *L, int what, int data);
349 ** miscellaneous functions
352 LUA_API int (lua_error) (lua_State *L);
354 LUA_API int (lua_next) (lua_State *L, int idx);
356 LUA_API void (lua_concat) (lua_State *L, int n);
357 LUA_API void (lua_len) (lua_State *L, int idx);
359 LUA_API size_t (lua_stringtonumber) (lua_State *L, const char *s);
361 LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
362 LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
367 ** {==============================================================
368 ** some useful macros
369 ** ===============================================================
372 #define lua_getextraspace(L) ((void *)((char *)(L) - LUA_EXTRASPACE))
374 #define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL)
375 #define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL)
377 #define lua_pop(L,n) lua_settop(L, -(n)-1)
379 #define lua_newtable(L) lua_createtable(L, 0, 0)
381 #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
383 #define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
385 #define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
386 #define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
387 #define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
388 #define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
389 #define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
390 #define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
391 #define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
392 #define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
394 #define lua_pushliteral(L, s) lua_pushstring(L, "" s)
396 #define lua_pushglobaltable(L) \
397 lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)
399 #define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
402 #define lua_insert(L,idx) lua_rotate(L, (idx), 1)
404 #define lua_remove(L,idx) (lua_rotate(L, (idx), -1), lua_pop(L, 1))
406 #define lua_replace(L,idx) (lua_copy(L, -1, (idx)), lua_pop(L, 1))
408 /* }============================================================== */
412 ** {==============================================================
413 ** compatibility macros for unsigned conversions
414 ** ===============================================================
416 #if defined(LUA_COMPAT_APIINTCASTS)
418 #define lua_pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n))
419 #define lua_tounsignedx(L,i,is) ((lua_Unsigned)lua_tointegerx(L,i,is))
420 #define lua_tounsigned(L,i) lua_tounsignedx(L,(i),NULL)
422 #endif
423 /* }============================================================== */
426 ** {======================================================================
427 ** Debug API
428 ** =======================================================================
433 ** Event codes
435 #define LUA_HOOKCALL 0
436 #define LUA_HOOKRET 1
437 #define LUA_HOOKLINE 2
438 #define LUA_HOOKCOUNT 3
439 #define LUA_HOOKTAILCALL 4
443 ** Event masks
445 #define LUA_MASKCALL (1 << LUA_HOOKCALL)
446 #define LUA_MASKRET (1 << LUA_HOOKRET)
447 #define LUA_MASKLINE (1 << LUA_HOOKLINE)
448 #define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
450 typedef struct lua_Debug lua_Debug; /* activation record */
453 /* Functions to be called by the debugger in specific events */
454 typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
457 LUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);
458 LUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);
459 LUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n);
460 LUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n);
461 LUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n);
462 LUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n);
464 LUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n);
465 LUA_API void (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,
466 int fidx2, int n2);
468 LUA_API void (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);
469 LUA_API lua_Hook (lua_gethook) (lua_State *L);
470 LUA_API int (lua_gethookmask) (lua_State *L);
471 LUA_API int (lua_gethookcount) (lua_State *L);
474 struct lua_Debug {
475 int event;
476 const char *name; /* (n) */
477 const char *namewhat; /* (n) 'global', 'local', 'field', 'method' */
478 const char *what; /* (S) 'Lua', 'C', 'main', 'tail' */
479 const char *source; /* (S) */
480 int currentline; /* (l) */
481 int linedefined; /* (S) */
482 int lastlinedefined; /* (S) */
483 unsigned char nups; /* (u) number of upvalues */
484 unsigned char nparams;/* (u) number of parameters */
485 char isvararg; /* (u) */
486 char istailcall; /* (t) */
487 char short_src[LUA_IDSIZE]; /* (S) */
488 /* private part */
489 struct CallInfo *i_ci; /* active function */
492 /* }====================================================================== */
495 /******************************************************************************
496 #ifdef _KERNEL
497 * Copyright (c) 2015, Lourival Vieira Neto <lneto@NetBSD.org>.
498 #endif
499 * Copyright (C) 1994-2015 Lua.org, PUC-Rio.
501 * Permission is hereby granted, free of charge, to any person obtaining
502 * a copy of this software and associated documentation files (the
503 * "Software"), to deal in the Software without restriction, including
504 * without limitation the rights to use, copy, modify, merge, publish,
505 * distribute, sublicense, and/or sell copies of the Software, and to
506 * permit persons to whom the Software is furnished to do so, subject to
507 * the following conditions:
509 * The above copyright notice and this permission notice shall be
510 * included in all copies or substantial portions of the Software.
512 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
513 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
514 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
515 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
516 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
517 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
518 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
519 ******************************************************************************/
522 #endif