$search
00001 /* 00002 * Copied from the Lua sources. 00003 */ 00004 00005 /* 00006 ** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $ 00007 ** Lua - An Extensible Extension Language 00008 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) 00009 ** See Copyright Notice at the end of this file 00010 */ 00011 00012 00013 #ifndef lua_h 00014 #define lua_h 00015 00016 #include <stdarg.h> 00017 #include <stddef.h> 00018 00019 00020 #include "luaconf.h" 00021 00022 00023 #define LUA_VERSION "Lua 5.1" 00024 #define LUA_RELEASE "Lua 5.1.4" 00025 #define LUA_VERSION_NUM 501 00026 #define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" 00027 #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" 00028 00029 00030 /* mark for precompiled code (`<esc>Lua') */ 00031 #define LUA_SIGNATURE "\033Lua" 00032 00033 /* option for multiple returns in `lua_pcall' and `lua_call' */ 00034 #define LUA_MULTRET (-1) 00035 00036 00037 /* 00038 ** pseudo-indices 00039 */ 00040 #define LUA_REGISTRYINDEX (-10000) 00041 #define LUA_ENVIRONINDEX (-10001) 00042 #define LUA_GLOBALSINDEX (-10002) 00043 #define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) 00044 00045 00046 /* thread status; 0 is OK */ 00047 #define LUA_YIELD 1 00048 #define LUA_ERRRUN 2 00049 #define LUA_ERRSYNTAX 3 00050 #define LUA_ERRMEM 4 00051 #define LUA_ERRERR 5 00052 00053 00054 typedef struct lua_State lua_State; 00055 00056 typedef int (*lua_CFunction) (lua_State *L); 00057 00058 00059 /* 00060 ** functions that read/write blocks when loading/dumping Lua chunks 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 ** prototype for memory-allocation functions 00069 */ 00070 typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); 00071 00072 00073 /* 00074 ** basic types 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 /* minimum Lua stack available to a C function */ 00089 #define LUA_MINSTACK 20 00090 00091 00092 /* 00093 ** generic extra include file 00094 */ 00095 #if defined(LUA_USER_H) 00096 #include LUA_USER_H 00097 #endif 00098 00099 00100 /* type of numbers in Lua */ 00101 typedef LUA_NUMBER lua_Number; 00102 00103 00104 /* type for integer functions */ 00105 typedef LUA_INTEGER lua_Integer; 00106 00107 00108 00109 /* 00110 ** state manipulation 00111 */ 00112 LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud); 00113 LUA_API void (lua_close) (lua_State *L); 00114 LUA_API lua_State *(lua_newthread) (lua_State *L); 00115 00116 LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); 00117 00118 00119 /* 00120 ** basic stack manipulation 00121 */ 00122 LUA_API int (lua_gettop) (lua_State *L); 00123 LUA_API void (lua_settop) (lua_State *L, int idx); 00124 LUA_API void (lua_pushvalue) (lua_State *L, int idx); 00125 LUA_API void (lua_remove) (lua_State *L, int idx); 00126 LUA_API void (lua_insert) (lua_State *L, int idx); 00127 LUA_API void (lua_replace) (lua_State *L, int idx); 00128 LUA_API int (lua_checkstack) (lua_State *L, int sz); 00129 00130 LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n); 00131 00132 00133 /* 00134 ** access functions (stack -> C) 00135 */ 00136 00137 LUA_API int (lua_isnumber) (lua_State *L, int idx); 00138 LUA_API int (lua_isstring) (lua_State *L, int idx); 00139 LUA_API int (lua_iscfunction) (lua_State *L, int idx); 00140 LUA_API int (lua_isuserdata) (lua_State *L, int idx); 00141 LUA_API int (lua_type) (lua_State *L, int idx); 00142 LUA_API const char *(lua_typename) (lua_State *L, int tp); 00143 00144 LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2); 00145 LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2); 00146 LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2); 00147 00148 LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx); 00149 LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx); 00150 LUA_API int (lua_toboolean) (lua_State *L, int idx); 00151 LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); 00152 LUA_API size_t (lua_objlen) (lua_State *L, int idx); 00153 LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); 00154 LUA_API void *(lua_touserdata) (lua_State *L, int idx); 00155 LUA_API lua_State *(lua_tothread) (lua_State *L, int idx); 00156 LUA_API const void *(lua_topointer) (lua_State *L, int idx); 00157 00158 00159 /* 00160 ** push functions (C -> stack) 00161 */ 00162 LUA_API void (lua_pushnil) (lua_State *L); 00163 LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); 00164 LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); 00165 LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l); 00166 LUA_API void (lua_pushstring) (lua_State *L, const char *s); 00167 LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, 00168 va_list argp); 00169 LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); 00170 LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n); 00171 LUA_API void (lua_pushboolean) (lua_State *L, int b); 00172 LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p); 00173 LUA_API int (lua_pushthread) (lua_State *L); 00174 00175 00176 /* 00177 ** get functions (Lua -> stack) 00178 */ 00179 LUA_API void (lua_gettable) (lua_State *L, int idx); 00180 LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); 00181 LUA_API void (lua_rawget) (lua_State *L, int idx); 00182 LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n); 00183 LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); 00184 LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); 00185 LUA_API int (lua_getmetatable) (lua_State *L, int objindex); 00186 LUA_API void (lua_getfenv) (lua_State *L, int idx); 00187 00188 00189 /* 00190 ** set functions (stack -> Lua) 00191 */ 00192 LUA_API void (lua_settable) (lua_State *L, int idx); 00193 LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); 00194 LUA_API void (lua_rawset) (lua_State *L, int idx); 00195 LUA_API void (lua_rawseti) (lua_State *L, int idx, int n); 00196 LUA_API int (lua_setmetatable) (lua_State *L, int objindex); 00197 LUA_API int (lua_setfenv) (lua_State *L, int idx); 00198 00199 00200 /* 00201 ** `load' and `call' functions (load and run Lua code) 00202 */ 00203 LUA_API void (lua_call) (lua_State *L, int nargs, int nresults); 00204 LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc); 00205 LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud); 00206 LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, 00207 const char *chunkname); 00208 00209 LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data); 00210 00211 00212 /* 00213 ** coroutine functions 00214 */ 00215 LUA_API int (lua_yield) (lua_State *L, int nresults); 00216 LUA_API int (lua_resume) (lua_State *L, int narg); 00217 LUA_API int (lua_status) (lua_State *L); 00218 00219 /* 00220 ** garbage-collection function and options 00221 */ 00222 00223 #define LUA_GCSTOP 0 00224 #define LUA_GCRESTART 1 00225 #define LUA_GCCOLLECT 2 00226 #define LUA_GCCOUNT 3 00227 #define LUA_GCCOUNTB 4 00228 #define LUA_GCSTEP 5 00229 #define LUA_GCSETPAUSE 6 00230 #define LUA_GCSETSTEPMUL 7 00231 00232 LUA_API int (lua_gc) (lua_State *L, int what, int data); 00233 00234 00235 /* 00236 ** miscellaneous functions 00237 */ 00238 00239 LUA_API int (lua_error) (lua_State *L); 00240 00241 LUA_API int (lua_next) (lua_State *L, int idx); 00242 00243 LUA_API void (lua_concat) (lua_State *L, int n); 00244 00245 LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); 00246 LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); 00247 00248 00249 00250 /* 00251 ** =============================================================== 00252 ** some useful macros 00253 ** =============================================================== 00254 */ 00255 00256 #define lua_pop(L,n) lua_settop(L, -(n)-1) 00257 00258 #define lua_newtable(L) lua_createtable(L, 0, 0) 00259 00260 #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) 00261 00262 #define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) 00263 00264 #define lua_strlen(L,i) lua_objlen(L, (i)) 00265 00266 #define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) 00267 #define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) 00268 #define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) 00269 #define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) 00270 #define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) 00271 #define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) 00272 #define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) 00273 #define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) 00274 00275 #define lua_pushliteral(L, s) \ 00276 lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) 00277 00278 #define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) 00279 #define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) 00280 00281 #define lua_tostring(L,i) lua_tolstring(L, (i), NULL) 00282 00283 00284 00285 /* 00286 ** compatibility macros and functions 00287 */ 00288 00289 #define lua_open() luaL_newstate() 00290 00291 #define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) 00292 00293 #define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0) 00294 00295 #define lua_Chunkreader lua_Reader 00296 #define lua_Chunkwriter lua_Writer 00297 00298 00299 /* hack */ 00300 LUA_API void lua_setlevel (lua_State *from, lua_State *to); 00301 00302 00303 /* 00304 ** {====================================================================== 00305 ** Debug API 00306 ** ======================================================================= 00307 */ 00308 00309 00310 /* 00311 ** Event codes 00312 */ 00313 #define LUA_HOOKCALL 0 00314 #define LUA_HOOKRET 1 00315 #define LUA_HOOKLINE 2 00316 #define LUA_HOOKCOUNT 3 00317 #define LUA_HOOKTAILRET 4 00318 00319 00320 /* 00321 ** Event masks 00322 */ 00323 #define LUA_MASKCALL (1 << LUA_HOOKCALL) 00324 #define LUA_MASKRET (1 << LUA_HOOKRET) 00325 #define LUA_MASKLINE (1 << LUA_HOOKLINE) 00326 #define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) 00327 00328 typedef struct lua_Debug lua_Debug; /* activation record */ 00329 00330 00331 /* Functions to be called by the debuger in specific events */ 00332 typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); 00333 00334 00335 LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar); 00336 LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); 00337 LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); 00338 LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); 00339 LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n); 00340 LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n); 00341 00342 LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count); 00343 LUA_API lua_Hook lua_gethook (lua_State *L); 00344 LUA_API int lua_gethookmask (lua_State *L); 00345 LUA_API int lua_gethookcount (lua_State *L); 00346 00347 00348 struct lua_Debug { 00349 int event; 00350 const char *name; /* (n) */ 00351 const char *namewhat; /* (n) `global', `local', `field', `method' */ 00352 const char *what; /* (S) `Lua', `C', `main', `tail' */ 00353 const char *source; /* (S) */ 00354 int currentline; /* (l) */ 00355 int nups; /* (u) number of upvalues */ 00356 int linedefined; /* (S) */ 00357 int lastlinedefined; /* (S) */ 00358 char short_src[LUA_IDSIZE]; /* (S) */ 00359 /* private part */ 00360 int i_ci; /* active function */ 00361 }; 00362 00363 /* }====================================================================== */ 00364 00365 00366 /****************************************************************************** 00367 * Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved. 00368 * 00369 * Permission is hereby granted, free of charge, to any person obtaining 00370 * a copy of this software and associated documentation files (the 00371 * "Software"), to deal in the Software without restriction, including 00372 * without limitation the rights to use, copy, modify, merge, publish, 00373 * distribute, sublicense, and/or sell copies of the Software, and to 00374 * permit persons to whom the Software is furnished to do so, subject to 00375 * the following conditions: 00376 * 00377 * The above copyright notice and this permission notice shall be 00378 * included in all copies or substantial portions of the Software. 00379 * 00380 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00381 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00382 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00383 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 00384 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 00385 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 00386 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00387 ******************************************************************************/ 00388 00389 00390 #endif