Nut/OS  4.10.3
API Reference
lua.h
Go to the documentation of this file.
00001 /*
00002 ** $Id: lua.h 2831 2009-12-08 14:19:44Z haraldkipp $
00003 ** Lua - An Extensible Extension Language
00004 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
00005 ** See Copyright Notice at the end of this file
00006 */
00007 
00008 
00009 #ifndef lua_h
00010 #define lua_h
00011 
00012 #include <stdarg.h>
00013 #include <stddef.h>
00014 
00015 #include <lua/luaconf.h>
00016 
00017 
00018 #define LUA_VERSION     "Lua 5.1"
00019 #define LUA_RELEASE     "Lua 5.1.4"
00020 #define LUA_VERSION_NUM 501
00021 #define LUA_COPYRIGHT   "Copyright (C) 1994-2008 Lua.org, PUC-Rio"
00022 #define LUA_AUTHORS     "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
00023 
00024 
00025 /* mark for precompiled code (`<esc>Lua') */
00026 #define LUA_SIGNATURE   "\033Lua"
00027 
00028 /* option for multiple returns in `lua_pcall' and `lua_call' */
00029 #define LUA_MULTRET     (-1)
00030 
00031 
00032 /*
00033 ** pseudo-indices
00034 */
00035 #define LUA_REGISTRYINDEX       (-10000)
00036 #define LUA_ENVIRONINDEX        (-10001)
00037 #define LUA_GLOBALSINDEX        (-10002)
00038 #define lua_upvalueindex(i)     (LUA_GLOBALSINDEX-(i))
00039 
00040 
00041 /* thread status; 0 is OK */
00042 #define LUA_YIELD       1
00043 #define LUA_ERRRUN      2
00044 #define LUA_ERRSYNTAX   3
00045 #define LUA_ERRMEM      4
00046 #define LUA_ERRERR      5
00047 
00048 
00049 typedef struct lua_State lua_State;
00050 
00051 typedef int (*lua_CFunction) (lua_State *L);
00052 
00053 
00054 /*
00055 ** functions that read/write blocks when loading/dumping Lua chunks
00056 */
00057 typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
00058 
00059 typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);
00060 
00061 
00062 /*
00063 ** prototype for memory-allocation functions
00064 */
00065 typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
00066 
00067 
00068 /*
00069 ** basic types
00070 */
00071 #define LUA_TNONE               (-1)
00072 
00073 #define LUA_TNIL                0
00074 #define LUA_TBOOLEAN            1
00075 #define LUA_TROTABLE  2
00076 #define LUA_TLIGHTFUNCTION  3
00077 #define LUA_TLIGHTUSERDATA      4
00078 #define LUA_TNUMBER             5
00079 #define LUA_TSTRING             6
00080 #define LUA_TTABLE              7
00081 #define LUA_TFUNCTION           8
00082 #define LUA_TUSERDATA           9
00083 #define LUA_TTHREAD             10
00084 
00085 /* minimum Lua stack available to a C function */
00086 #define LUA_MINSTACK    20
00087 
00088 
00089 /*
00090 ** generic extra include file
00091 */
00092 #if defined(LUA_USER_H)
00093 #include LUA_USER_H
00094 #endif
00095 
00096 
00097 /* type of numbers in Lua */
00098 typedef LUA_NUMBER lua_Number;
00099 
00100 
00101 /* type for integer functions */
00102 typedef LUA_INTEGER lua_Integer;
00103 
00104 
00105 
00106 /*
00107 ** state manipulation
00108 */
00109 LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
00110 LUA_API void       (lua_close) (lua_State *L);
00111 LUA_API lua_State *(lua_newthread) (lua_State *L);
00112 
00113 LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
00114 
00115 
00116 /*
00117 ** basic stack manipulation
00118 */
00119 LUA_API int   (lua_gettop) (lua_State *L);
00120 LUA_API void  (lua_settop) (lua_State *L, int idx);
00121 LUA_API void  (lua_pushvalue) (lua_State *L, int idx);
00122 LUA_API void  (lua_remove) (lua_State *L, int idx);
00123 LUA_API void  (lua_insert) (lua_State *L, int idx);
00124 LUA_API void  (lua_replace) (lua_State *L, int idx);
00125 LUA_API int   (lua_checkstack) (lua_State *L, int sz);
00126 
00127 LUA_API void  (lua_xmove) (lua_State *from, lua_State *to, int n);
00128 
00129 
00130 /*
00131 ** access functions (stack -> C)
00132 */
00133 
00134 LUA_API int             (lua_isnumber) (lua_State *L, int idx);
00135 LUA_API int             (lua_isstring) (lua_State *L, int idx);
00136 LUA_API int             (lua_iscfunction) (lua_State *L, int idx);
00137 LUA_API int             (lua_isuserdata) (lua_State *L, int idx);
00138 LUA_API int             (lua_type) (lua_State *L, int idx);
00139 LUA_API const char     *(lua_typename) (lua_State *L, int tp);
00140 
00141 LUA_API int            (lua_equal) (lua_State *L, int idx1, int idx2);
00142 LUA_API int            (lua_rawequal) (lua_State *L, int idx1, int idx2);
00143 LUA_API int            (lua_lessthan) (lua_State *L, int idx1, int idx2);
00144 
00145 LUA_API lua_Number      (lua_tonumber) (lua_State *L, int idx);
00146 LUA_API lua_Integer     (lua_tointeger) (lua_State *L, int idx);
00147 LUA_API int             (lua_toboolean) (lua_State *L, int idx);
00148 LUA_API const char     *(lua_tolstring) (lua_State *L, int idx, size_t *len);
00149 LUA_API size_t          (lua_objlen) (lua_State *L, int idx);
00150 LUA_API lua_CFunction   (lua_tocfunction) (lua_State *L, int idx);
00151 LUA_API void           *(lua_touserdata) (lua_State *L, int idx);
00152 LUA_API lua_State      *(lua_tothread) (lua_State *L, int idx);
00153 LUA_API const void     *(lua_topointer) (lua_State *L, int idx);
00154 
00155 
00156 /*
00157 ** push functions (C -> stack)
00158 */
00159 LUA_API void  (lua_pushnil) (lua_State *L);
00160 LUA_API void  (lua_pushnumber) (lua_State *L, lua_Number n);
00161 LUA_API void  (lua_pushinteger) (lua_State *L, lua_Integer n);
00162 LUA_API void  (lua_pushlstring) (lua_State *L, const char *s, size_t l);
00163 LUA_API void  (lua_pushstring) (lua_State *L, const char *s);
00164 LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
00165                                                       va_list argp);
00166 LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
00167 LUA_API void  (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
00168 LUA_API void  (lua_pushboolean) (lua_State *L, int b);
00169 LUA_API void  (lua_pushlightuserdata) (lua_State *L, void *p);
00170 LUA_API void  (lua_pushlightfunction) (lua_State *L, void *p);
00171 LUA_API void  (lua_pushrotable) (lua_State *L, void *p);
00172 LUA_API int   (lua_pushthread) (lua_State *L);
00173 
00174 
00175 /*
00176 ** get functions (Lua -> stack)
00177 */
00178 LUA_API void  (lua_gettable) (lua_State *L, int idx);
00179 LUA_API void  (lua_getfield) (lua_State *L, int idx, const char *k);
00180 LUA_API void  (lua_rawget) (lua_State *L, int idx);
00181 LUA_API void  (lua_rawgeti) (lua_State *L, int idx, int n);
00182 LUA_API void  (lua_createtable) (lua_State *L, int narr, int nrec);
00183 LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
00184 LUA_API int   (lua_getmetatable) (lua_State *L, int objindex);
00185 LUA_API void  (lua_getfenv) (lua_State *L, int idx);
00186 
00187 
00188 /*
00189 ** set functions (stack -> Lua)
00190 */
00191 LUA_API void  (lua_settable) (lua_State *L, int idx);
00192 LUA_API void  (lua_setfield) (lua_State *L, int idx, const char *k);
00193 LUA_API void  (lua_rawset) (lua_State *L, int idx);
00194 LUA_API void  (lua_rawseti) (lua_State *L, int idx, int n);
00195 LUA_API int   (lua_setmetatable) (lua_State *L, int objindex);
00196 LUA_API int   (lua_setfenv) (lua_State *L, int idx);
00197 
00198 
00199 /*
00200 ** `load' and `call' functions (load and run Lua code)
00201 */
00202 LUA_API void  (lua_call) (lua_State *L, int nargs, int nresults);
00203 LUA_API int   (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
00204 LUA_API int   (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);
00205 LUA_API int   (lua_load) (lua_State *L, lua_Reader reader, void *dt,
00206                                         const char *chunkname);
00207 
00208 LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
00209 
00210 
00211 /*
00212 ** coroutine functions
00213 */
00214 LUA_API int  (lua_yield) (lua_State *L, int nresults);
00215 LUA_API int  (lua_resume) (lua_State *L, int narg);
00216 LUA_API int  (lua_status) (lua_State *L);
00217 
00218 /*
00219 ** garbage-collection function and options
00220 */
00221 
00222 #define LUA_GCSTOP              0
00223 #define LUA_GCRESTART           1
00224 #define LUA_GCCOLLECT           2
00225 #define LUA_GCCOUNT             3
00226 #define LUA_GCCOUNTB            4
00227 #define LUA_GCSTEP              5
00228 #define LUA_GCSETPAUSE          6
00229 #define LUA_GCSETSTEPMUL        7
00230 
00231 LUA_API int (lua_gc) (lua_State *L, int what, int data);
00232 
00233 
00234 /*
00235 ** miscellaneous functions
00236 */
00237 
00238 LUA_API int   (lua_error) (lua_State *L);
00239 
00240 LUA_API int   (lua_next) (lua_State *L, int idx);
00241 
00242 LUA_API void  (lua_concat) (lua_State *L, int n);
00243 
00244 LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
00245 LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
00246 
00247 
00248 
00249 /* 
00250 ** ===============================================================
00251 ** some useful macros
00252 ** ===============================================================
00253 */
00254 
00255 #define lua_pop(L,n)            lua_settop(L, -(n)-1)
00256 
00257 #define lua_newtable(L)         lua_createtable(L, 0, 0)
00258 
00259 #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
00260 
00261 #define lua_pushcfunction(L,f)  lua_pushcclosure(L, (f), 0)
00262 
00263 #define lua_strlen(L,i)         lua_objlen(L, (i))
00264 
00265 #define lua_isfunction(L,n)     (lua_type(L, (n)) == LUA_TFUNCTION)
00266 #define lua_islightfunction(L,n) (lua_type(L, (n)) == LUA_TLIGHTFUNCTION)
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