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