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