rlm@1: /* rlm@1: ** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $ rlm@1: ** Lua - An Extensible Extension Language rlm@1: ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) rlm@1: ** See Copyright Notice at the end of this file rlm@1: */ rlm@1: rlm@1: rlm@1: #ifndef lua_h rlm@1: #define lua_h rlm@1: rlm@1: #include rlm@1: #include rlm@1: rlm@1: rlm@1: #include "luaconf.h" rlm@1: rlm@1: rlm@1: #define LUA_VERSION "Lua 5.1" rlm@1: #define LUA_RELEASE "Lua 5.1.4" rlm@1: #define LUA_VERSION_NUM 501 rlm@1: #define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" rlm@1: #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" rlm@1: rlm@1: rlm@1: /* mark for precompiled code (`Lua') */ rlm@1: #define LUA_SIGNATURE "\033Lua" rlm@1: rlm@1: /* option for multiple returns in `lua_pcall' and `lua_call' */ rlm@1: #define LUA_MULTRET (-1) rlm@1: rlm@1: rlm@1: /* rlm@1: ** pseudo-indices rlm@1: */ rlm@1: #define LUA_REGISTRYINDEX (-10000) rlm@1: #define LUA_ENVIRONINDEX (-10001) rlm@1: #define LUA_GLOBALSINDEX (-10002) rlm@1: #define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) rlm@1: rlm@1: rlm@1: /* thread status; 0 is OK */ rlm@1: #define LUA_YIELD 1 rlm@1: #define LUA_ERRRUN 2 rlm@1: #define LUA_ERRSYNTAX 3 rlm@1: #define LUA_ERRMEM 4 rlm@1: #define LUA_ERRERR 5 rlm@1: rlm@1: rlm@1: typedef struct lua_State lua_State; rlm@1: rlm@1: typedef int (*lua_CFunction) (lua_State *L); rlm@1: rlm@1: rlm@1: /* rlm@1: ** functions that read/write blocks when loading/dumping Lua chunks rlm@1: */ rlm@1: typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); rlm@1: rlm@1: typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud); rlm@1: rlm@1: rlm@1: /* rlm@1: ** prototype for memory-allocation functions rlm@1: */ rlm@1: typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); rlm@1: rlm@1: rlm@1: /* rlm@1: ** basic types rlm@1: */ rlm@1: #define LUA_TNONE (-1) rlm@1: rlm@1: #define LUA_TNIL 0 rlm@1: #define LUA_TBOOLEAN 1 rlm@1: #define LUA_TLIGHTUSERDATA 2 rlm@1: #define LUA_TNUMBER 3 rlm@1: #define LUA_TSTRING 4 rlm@1: #define LUA_TTABLE 5 rlm@1: #define LUA_TFUNCTION 6 rlm@1: #define LUA_TUSERDATA 7 rlm@1: #define LUA_TTHREAD 8 rlm@1: rlm@1: rlm@1: rlm@1: /* minimum Lua stack available to a C function */ rlm@1: #define LUA_MINSTACK 20 rlm@1: rlm@1: rlm@1: /* rlm@1: ** generic extra include file rlm@1: */ rlm@1: #if defined(LUA_USER_H) rlm@1: #include LUA_USER_H rlm@1: #endif rlm@1: rlm@1: rlm@1: /* type of numbers in Lua */ rlm@1: typedef LUA_NUMBER lua_Number; rlm@1: rlm@1: rlm@1: /* type for integer functions */ rlm@1: typedef LUA_INTEGER lua_Integer; rlm@1: rlm@1: rlm@1: rlm@1: /* rlm@1: ** state manipulation rlm@1: */ rlm@1: LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud); rlm@1: LUA_API void (lua_close) (lua_State *L); rlm@1: LUA_API lua_State *(lua_newthread) (lua_State *L); rlm@1: rlm@1: LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); rlm@1: rlm@1: rlm@1: /* rlm@1: ** basic stack manipulation rlm@1: */ rlm@1: LUA_API int (lua_gettop) (lua_State *L); rlm@1: LUA_API void (lua_settop) (lua_State *L, int idx); rlm@1: LUA_API void (lua_pushvalue) (lua_State *L, int idx); rlm@1: LUA_API void (lua_remove) (lua_State *L, int idx); rlm@1: LUA_API void (lua_insert) (lua_State *L, int idx); rlm@1: LUA_API void (lua_replace) (lua_State *L, int idx); rlm@1: LUA_API int (lua_checkstack) (lua_State *L, int sz); rlm@1: rlm@1: LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n); rlm@1: rlm@1: rlm@1: /* rlm@1: ** access functions (stack -> C) rlm@1: */ rlm@1: rlm@1: LUA_API int (lua_isnumber) (lua_State *L, int idx); rlm@1: LUA_API int (lua_isstring) (lua_State *L, int idx); rlm@1: LUA_API int (lua_iscfunction) (lua_State *L, int idx); rlm@1: LUA_API int (lua_isuserdata) (lua_State *L, int idx); rlm@1: LUA_API int (lua_type) (lua_State *L, int idx); rlm@1: LUA_API const char *(lua_typename) (lua_State *L, int tp); rlm@1: rlm@1: LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2); rlm@1: LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2); rlm@1: LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2); rlm@1: rlm@1: LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx); rlm@1: LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx); rlm@1: LUA_API int (lua_toboolean) (lua_State *L, int idx); rlm@1: LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); rlm@1: LUA_API size_t (lua_objlen) (lua_State *L, int idx); rlm@1: LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); rlm@1: LUA_API void *(lua_touserdata) (lua_State *L, int idx); rlm@1: LUA_API lua_State *(lua_tothread) (lua_State *L, int idx); rlm@1: LUA_API const void *(lua_topointer) (lua_State *L, int idx); rlm@1: rlm@1: rlm@1: /* rlm@1: ** push functions (C -> stack) rlm@1: */ rlm@1: LUA_API void (lua_pushnil) (lua_State *L); rlm@1: LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); rlm@1: LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); rlm@1: LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l); rlm@1: LUA_API void (lua_pushstring) (lua_State *L, const char *s); rlm@1: LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, rlm@1: va_list argp); rlm@1: LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); rlm@1: LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n); rlm@1: LUA_API void (lua_pushboolean) (lua_State *L, int b); rlm@1: LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p); rlm@1: LUA_API int (lua_pushthread) (lua_State *L); rlm@1: rlm@1: rlm@1: /* rlm@1: ** get functions (Lua -> stack) rlm@1: */ rlm@1: LUA_API void (lua_gettable) (lua_State *L, int idx); rlm@1: LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); rlm@1: LUA_API void (lua_rawget) (lua_State *L, int idx); rlm@1: LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n); rlm@1: LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); rlm@1: LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); rlm@1: LUA_API int (lua_getmetatable) (lua_State *L, int objindex); rlm@1: LUA_API void (lua_getfenv) (lua_State *L, int idx); rlm@1: rlm@1: rlm@1: /* rlm@1: ** set functions (stack -> Lua) rlm@1: */ rlm@1: LUA_API void (lua_settable) (lua_State *L, int idx); rlm@1: LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); rlm@1: LUA_API void (lua_rawset) (lua_State *L, int idx); rlm@1: LUA_API void (lua_rawseti) (lua_State *L, int idx, int n); rlm@1: LUA_API int (lua_setmetatable) (lua_State *L, int objindex); rlm@1: LUA_API int (lua_setfenv) (lua_State *L, int idx); rlm@1: rlm@1: rlm@1: /* rlm@1: ** `load' and `call' functions (load and run Lua code) rlm@1: */ rlm@1: LUA_API void (lua_call) (lua_State *L, int nargs, int nresults); rlm@1: LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc); rlm@1: LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud); rlm@1: LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, rlm@1: const char *chunkname); rlm@1: rlm@1: LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data); rlm@1: rlm@1: rlm@1: /* rlm@1: ** coroutine functions rlm@1: */ rlm@1: LUA_API int (lua_yield) (lua_State *L, int nresults); rlm@1: LUA_API int (lua_resume) (lua_State *L, int narg); rlm@1: LUA_API int (lua_status) (lua_State *L); rlm@1: rlm@1: /* rlm@1: ** garbage-collection function and options rlm@1: */ rlm@1: rlm@1: #define LUA_GCSTOP 0 rlm@1: #define LUA_GCRESTART 1 rlm@1: #define LUA_GCCOLLECT 2 rlm@1: #define LUA_GCCOUNT 3 rlm@1: #define LUA_GCCOUNTB 4 rlm@1: #define LUA_GCSTEP 5 rlm@1: #define LUA_GCSETPAUSE 6 rlm@1: #define LUA_GCSETSTEPMUL 7 rlm@1: rlm@1: LUA_API int (lua_gc) (lua_State *L, int what, int data); rlm@1: rlm@1: rlm@1: /* rlm@1: ** miscellaneous functions rlm@1: */ rlm@1: rlm@1: LUA_API int (lua_error) (lua_State *L); rlm@1: rlm@1: LUA_API int (lua_next) (lua_State *L, int idx); rlm@1: rlm@1: LUA_API void (lua_concat) (lua_State *L, int n); rlm@1: rlm@1: LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); rlm@1: LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); rlm@1: rlm@1: rlm@1: rlm@1: /* rlm@1: ** =============================================================== rlm@1: ** some useful macros rlm@1: ** =============================================================== rlm@1: */ rlm@1: rlm@1: #define lua_pop(L,n) lua_settop(L, -(n)-1) rlm@1: rlm@1: #define lua_newtable(L) lua_createtable(L, 0, 0) rlm@1: rlm@1: #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) rlm@1: rlm@1: #define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) rlm@1: rlm@1: #define lua_strlen(L,i) lua_objlen(L, (i)) rlm@1: rlm@1: #define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) rlm@1: #define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) rlm@1: #define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) rlm@1: #define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) rlm@1: #define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) rlm@1: #define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) rlm@1: #define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) rlm@1: #define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) rlm@1: rlm@1: #define lua_pushliteral(L, s) \ rlm@1: lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) rlm@1: rlm@1: #define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) rlm@1: #define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) rlm@1: rlm@1: #define lua_tostring(L,i) lua_tolstring(L, (i), NULL) rlm@1: rlm@1: rlm@1: rlm@1: /* rlm@1: ** compatibility macros and functions rlm@1: */ rlm@1: rlm@1: #define lua_open() luaL_newstate() rlm@1: rlm@1: #define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) rlm@1: rlm@1: #define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0) rlm@1: rlm@1: #define lua_Chunkreader lua_Reader rlm@1: #define lua_Chunkwriter lua_Writer rlm@1: rlm@1: rlm@1: /* hack */ rlm@1: LUA_API void lua_setlevel (lua_State *from, lua_State *to); rlm@1: rlm@1: rlm@1: /* rlm@1: ** {====================================================================== rlm@1: ** Debug API rlm@1: ** ======================================================================= rlm@1: */ rlm@1: rlm@1: rlm@1: /* rlm@1: ** Event codes rlm@1: */ rlm@1: #define LUA_HOOKCALL 0 rlm@1: #define LUA_HOOKRET 1 rlm@1: #define LUA_HOOKLINE 2 rlm@1: #define LUA_HOOKCOUNT 3 rlm@1: #define LUA_HOOKTAILRET 4 rlm@1: rlm@1: rlm@1: /* rlm@1: ** Event masks rlm@1: */ rlm@1: #define LUA_MASKCALL (1 << LUA_HOOKCALL) rlm@1: #define LUA_MASKRET (1 << LUA_HOOKRET) rlm@1: #define LUA_MASKLINE (1 << LUA_HOOKLINE) rlm@1: #define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) rlm@1: rlm@1: typedef struct lua_Debug lua_Debug; /* activation record */ rlm@1: rlm@1: rlm@1: /* Functions to be called by the debuger in specific events */ rlm@1: typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); rlm@1: rlm@1: rlm@1: LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar); rlm@1: LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); rlm@1: LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); rlm@1: LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); rlm@1: LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n); rlm@1: LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n); rlm@1: rlm@1: LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count); rlm@1: LUA_API lua_Hook lua_gethook (lua_State *L); rlm@1: LUA_API int lua_gethookmask (lua_State *L); rlm@1: LUA_API int lua_gethookcount (lua_State *L); rlm@1: rlm@1: rlm@1: struct lua_Debug { rlm@1: int event; rlm@1: const char *name; /* (n) */ rlm@1: const char *namewhat; /* (n) `global', `local', `field', `method' */ rlm@1: const char *what; /* (S) `Lua', `C', `main', `tail' */ rlm@1: const char *source; /* (S) */ rlm@1: int currentline; /* (l) */ rlm@1: int nups; /* (u) number of upvalues */ rlm@1: int linedefined; /* (S) */ rlm@1: int lastlinedefined; /* (S) */ rlm@1: char short_src[LUA_IDSIZE]; /* (S) */ rlm@1: /* private part */ rlm@1: int i_ci; /* active function */ rlm@1: }; rlm@1: rlm@1: /* }====================================================================== */ rlm@1: rlm@1: rlm@1: /****************************************************************************** rlm@1: * Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved. rlm@1: * rlm@1: * Permission is hereby granted, free of charge, to any person obtaining rlm@1: * a copy of this software and associated documentation files (the rlm@1: * "Software"), to deal in the Software without restriction, including rlm@1: * without limitation the rights to use, copy, modify, merge, publish, rlm@1: * distribute, sublicense, and/or sell copies of the Software, and to rlm@1: * permit persons to whom the Software is furnished to do so, subject to rlm@1: * the following conditions: rlm@1: * rlm@1: * The above copyright notice and this permission notice shall be rlm@1: * included in all copies or substantial portions of the Software. rlm@1: * rlm@1: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, rlm@1: * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF rlm@1: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. rlm@1: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY rlm@1: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, rlm@1: * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE rlm@1: * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. rlm@1: ******************************************************************************/ rlm@1: rlm@1: rlm@1: #endif