00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef lua_h
00010 #define lua_h
00011
00012 #include <stdarg.h>
00013 #include <stddef.h>
00014
00015
00016 #include "luaconf.h"
00017
00018
00019 #define LUA_VERSION_MAJOR "5"
00020 #define LUA_VERSION_MINOR "2"
00021 #define LUA_VERSION_NUM 502
00022 #define LUA_VERSION_RELEASE "0"
00023
00024 #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
00025 #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
00026 #define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2011 Lua.org, PUC-Rio"
00027 #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
00028
00029
00030
00031 #define LUA_SIGNATURE "\033Lua"
00032
00033
00034 #define LUA_MULTRET (-1)
00035
00036
00037
00038
00039
00040 #define LUA_REGISTRYINDEX LUAI_FIRSTPSEUDOIDX
00041 #define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i))
00042
00043
00044
00045 #define LUA_OK 0
00046 #define LUA_YIELD 1
00047 #define LUA_ERRRUN 2
00048 #define LUA_ERRSYNTAX 3
00049 #define LUA_ERRMEM 4
00050 #define LUA_ERRGCMM 5
00051 #define LUA_ERRERR 6
00052
00053
00054 typedef struct lua_State lua_State;
00055
00056 typedef int (*lua_CFunction) (lua_State *L);
00057
00058
00059
00060
00061
00062 typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
00063
00064 typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);
00065
00066
00067
00068
00069
00070 typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
00071
00072
00073
00074
00075
00076 #define LUA_TNONE (-1)
00077
00078 #define LUA_TNIL 0
00079 #define LUA_TBOOLEAN 1
00080 #define LUA_TLIGHTUSERDATA 2
00081 #define LUA_TNUMBER 3
00082 #define LUA_TSTRING 4
00083 #define LUA_TTABLE 5
00084 #define LUA_TFUNCTION 6
00085 #define LUA_TUSERDATA 7
00086 #define LUA_TTHREAD 8
00087
00088 #define LUA_NUMTAGS 9
00089
00090
00091
00092
00093 #define LUA_MINSTACK 20
00094
00095
00096
00097 #define LUA_RIDX_MAINTHREAD 1
00098 #define LUA_RIDX_GLOBALS 2
00099 #define LUA_RIDX_LAST LUA_RIDX_GLOBALS
00100
00101
00102
00103 typedef LUA_NUMBER lua_Number;
00104
00105
00106
00107 typedef LUA_INTEGER lua_Integer;
00108
00109
00110 typedef LUA_UNSIGNED lua_Unsigned;
00111
00112
00113
00114
00115
00116
00117 #if defined(LUA_USER_H)
00118 #include LUA_USER_H
00119 #endif
00120
00121
00122
00123
00124
00125
00126 LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
00127 LUA_API void (lua_close) (lua_State *L);
00128 LUA_API lua_State *(lua_newthread) (lua_State *L);
00129
00130 LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
00131
00132
00133 LUA_API const lua_Number *(lua_version) (lua_State *L);
00134
00135
00136
00137
00138
00139 LUA_API int (lua_absindex) (lua_State *L, int idx);
00140 LUA_API int (lua_gettop) (lua_State *L);
00141 LUA_API void (lua_settop) (lua_State *L, int idx);
00142 LUA_API void (lua_pushvalue) (lua_State *L, int idx);
00143 LUA_API void (lua_remove) (lua_State *L, int idx);
00144 LUA_API void (lua_insert) (lua_State *L, int idx);
00145 LUA_API void (lua_replace) (lua_State *L, int idx);
00146 LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx);
00147 LUA_API int (lua_checkstack) (lua_State *L, int sz);
00148
00149 LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
00150
00151
00152
00153
00154
00155
00156 LUA_API int (lua_isnumber) (lua_State *L, int idx);
00157 LUA_API int (lua_isstring) (lua_State *L, int idx);
00158 LUA_API int (lua_iscfunction) (lua_State *L, int idx);
00159 LUA_API int (lua_isuserdata) (lua_State *L, int idx);
00160 LUA_API int (lua_type) (lua_State *L, int idx);
00161 LUA_API const char *(lua_typename) (lua_State *L, int tp);
00162
00163 LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
00164 LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);
00165 LUA_API lua_Unsigned (lua_tounsignedx) (lua_State *L, int idx, int *isnum);
00166 LUA_API int (lua_toboolean) (lua_State *L, int idx);
00167 LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
00168 LUA_API size_t (lua_rawlen) (lua_State *L, int idx);
00169 LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
00170 LUA_API void *(lua_touserdata) (lua_State *L, int idx);
00171 LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
00172 LUA_API const void *(lua_topointer) (lua_State *L, int idx);
00173
00174
00175
00176
00177
00178
00179 #define LUA_OPADD 0
00180 #define LUA_OPSUB 1
00181 #define LUA_OPMUL 2
00182 #define LUA_OPDIV 3
00183 #define LUA_OPMOD 4
00184 #define LUA_OPPOW 5
00185 #define LUA_OPUNM 6
00186
00187 LUA_API void (lua_arith) (lua_State *L, int op);
00188
00189 #define LUA_OPEQ 0
00190 #define LUA_OPLT 1
00191 #define LUA_OPLE 2
00192
00193 LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
00194 LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op);
00195
00196
00197
00198
00199
00200 LUA_API void (lua_pushnil) (lua_State *L);
00201 LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
00202 LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
00203 LUA_API void (lua_pushunsigned) (lua_State *L, lua_Unsigned n);
00204 LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t l);
00205 LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
00206 LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
00207 va_list argp);
00208 LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
00209 LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
00210 LUA_API void (lua_pushboolean) (lua_State *L, int b);
00211 LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
00212 LUA_API int (lua_pushthread) (lua_State *L);
00213
00214
00215
00216
00217
00218 LUA_API void (lua_getglobal) (lua_State *L, const char *var);
00219 LUA_API void (lua_gettable) (lua_State *L, int idx);
00220 LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k);
00221 LUA_API void (lua_rawget) (lua_State *L, int idx);
00222 LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n);
00223 LUA_API void (lua_rawgetp) (lua_State *L, int idx, const void *p);
00224 LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
00225 LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
00226 LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
00227 LUA_API void (lua_getuservalue) (lua_State *L, int idx);
00228
00229
00230
00231
00232
00233 LUA_API void (lua_setglobal) (lua_State *L, const char *var);
00234 LUA_API void (lua_settable) (lua_State *L, int idx);
00235 LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
00236 LUA_API void (lua_rawset) (lua_State *L, int idx);
00237 LUA_API void (lua_rawseti) (lua_State *L, int idx, int n);
00238 LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p);
00239 LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
00240 LUA_API void (lua_setuservalue) (lua_State *L, int idx);
00241
00242
00243
00244
00245
00246 LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults, int ctx,
00247 lua_CFunction k);
00248 #define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL)
00249
00250 LUA_API int (lua_getctx) (lua_State *L, int *ctx);
00251
00252 LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
00253 int ctx, lua_CFunction k);
00254 #define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL)
00255
00256 LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
00257 const char *chunkname,
00258 const char *mode);
00259
00260 LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
00261
00262
00263
00264
00265
00266 LUA_API int (lua_yieldk) (lua_State *L, int nresults, int ctx,
00267 lua_CFunction k);
00268 #define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
00269 LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg);
00270 LUA_API int (lua_status) (lua_State *L);
00271
00272
00273
00274
00275
00276 #define LUA_GCSTOP 0
00277 #define LUA_GCRESTART 1
00278 #define LUA_GCCOLLECT 2
00279 #define LUA_GCCOUNT 3
00280 #define LUA_GCCOUNTB 4
00281 #define LUA_GCSTEP 5
00282 #define LUA_GCSETPAUSE 6
00283 #define LUA_GCSETSTEPMUL 7
00284 #define LUA_GCSETMAJORINC 8
00285 #define LUA_GCISRUNNING 9
00286 #define LUA_GCGEN 10
00287 #define LUA_GCINC 11
00288
00289 LUA_API int (lua_gc) (lua_State *L, int what, int data);
00290
00291
00292
00293
00294
00295
00296 LUA_API int (lua_error) (lua_State *L);
00297
00298 LUA_API int (lua_next) (lua_State *L, int idx);
00299
00300 LUA_API void (lua_concat) (lua_State *L, int n);
00301 LUA_API void (lua_len) (lua_State *L, int idx);
00302
00303 LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
00304 LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 #define lua_tonumber(L,i) lua_tonumberx(L,i,NULL)
00315 #define lua_tointeger(L,i) lua_tointegerx(L,i,NULL)
00316 #define lua_tounsigned(L,i) lua_tounsignedx(L,i,NULL)
00317
00318 #define lua_pop(L,n) lua_settop(L, -(n)-1)
00319
00320 #define lua_newtable(L) lua_createtable(L, 0, 0)
00321
00322 #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
00323
00324 #define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
00325
00326 #define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
00327 #define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
00328 #define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
00329 #define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
00330 #define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
00331 #define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
00332 #define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
00333 #define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
00334
00335 #define lua_pushliteral(L, s) \
00336 lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
00337
00338 #define lua_pushglobaltable(L) \
00339 lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)
00340
00341 #define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355 #define LUA_HOOKCALL 0
00356 #define LUA_HOOKRET 1
00357 #define LUA_HOOKLINE 2
00358 #define LUA_HOOKCOUNT 3
00359 #define LUA_HOOKTAILCALL 4
00360
00361
00362
00363
00364
00365 #define LUA_MASKCALL (1 << LUA_HOOKCALL)
00366 #define LUA_MASKRET (1 << LUA_HOOKRET)
00367 #define LUA_MASKLINE (1 << LUA_HOOKLINE)
00368 #define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
00369
00370 typedef struct lua_Debug lua_Debug;
00371
00372
00373
00374 typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
00375
00376
00377 LUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);
00378 LUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);
00379 LUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n);
00380 LUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n);
00381 LUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n);
00382 LUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n);
00383
00384 LUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n);
00385 LUA_API void (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,
00386 int fidx2, int n2);
00387
00388 LUA_API int (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);
00389 LUA_API lua_Hook (lua_gethook) (lua_State *L);
00390 LUA_API int (lua_gethookmask) (lua_State *L);
00391 LUA_API int (lua_gethookcount) (lua_State *L);
00392
00393
00394 struct lua_Debug {
00395 int event;
00396 const char *name;
00397 const char *namewhat;
00398 const char *what;
00399 const char *source;
00400 int currentline;
00401 int linedefined;
00402 int lastlinedefined;
00403 unsigned char nups;
00404 unsigned char nparams;
00405 char isvararg;
00406 char istailcall;
00407 char short_src[LUA_IDSIZE];
00408
00409 struct CallInfo *i_ci;
00410 };
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439 #endif