lua.h

Go to the documentation of this file.
00001 /*
00002 ** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $
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 
00016 #include "luaconf.h"
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_TLIGHTUSERDATA  2
00076 #define LUA_TNUMBER   3
00077 #define LUA_TSTRING   4
00078 #define LUA_TTABLE    5
00079 #define LUA_TFUNCTION   6
00080 #define LUA_TUSERDATA   7
00081 #define LUA_TTHREAD   8
00082 
00083 
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 int   (lua_pushthread) (lua_State *L);
00171 
00172 
00173 /*
00174 ** get functions (Lua -> stack)
00175 */
00176 LUA_API void  (lua_gettable) (lua_State *L, int idx);
00177 LUA_API void  (lua_getfield) (lua_State *L, int idx, const char *k);
00178 LUA_API void  (lua_rawget) (lua_State *L, int idx);
00179 LUA_API void  (lua_rawgeti) (lua_State *L, int idx, int n);
00180 LUA_API void  (lua_createtable) (lua_State *L, int narr, int nrec);
00181 LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
00182 LUA_API int   (lua_getmetatable) (lua_State *L, int objindex);
00183 LUA_API void  (lua_getfenv) (lua_State *L, int idx);
00184 
00185 
00186 /*
00187 ** set functions (stack -> Lua)
00188 */
00189 LUA_API void  (lua_settable) (lua_State *L, int idx);
00190 LUA_API void  (lua_setfield) (lua_State *L, int idx, const char *k);
00191 LUA_API void  (lua_rawset) (lua_State *L, int idx);
00192 LUA_API void  (lua_rawseti) (lua_State *L, int idx, int n);
00193 LUA_API int   (lua_setmetatable) (lua_State *L, int objindex);
00194 LUA_API int   (lua_setfenv) (lua_State *L, int idx);
00195 
00196 
00197 /*
00198 ** `load' and `call' functions (load and run Lua code)
00199 */
00200 LUA_API void  (lua_call) (lua_State *L, int nargs, int nresults);
00201 LUA_API int   (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
00202 LUA_API int   (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);
00203 LUA_API int   (lua_load) (lua_State *L, lua_Reader reader, void *dt,
00204                                         const char *chunkname);
00205 
00206 LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
00207 
00208 
00209 /*
00210 ** coroutine functions
00211 */
00212 LUA_API int  (lua_yield) (lua_State *L, int nresults);
00213 LUA_API int  (lua_resume) (lua_State *L, int narg);
00214 LUA_API int  (lua_status) (lua_State *L);
00215 
00216 /*
00217 ** garbage-collection function and options
00218 */
00219 
00220 #define LUA_GCSTOP    0
00221 #define LUA_GCRESTART   1
00222 #define LUA_GCCOLLECT   2
00223 #define LUA_GCCOUNT   3
00224 #define LUA_GCCOUNTB    4
00225 #define LUA_GCSTEP    5
00226 #define LUA_GCSETPAUSE    6
00227 #define LUA_GCSETSTEPMUL  7
00228 
00229 LUA_API int (lua_gc) (lua_State *L, int what, int data);
00230 
00231 
00232 /*
00233 ** miscellaneous functions
00234 */
00235 
00236 LUA_API int   (lua_error) (lua_State *L);
00237 
00238 LUA_API int   (lua_next) (lua_State *L, int idx);
00239 
00240 LUA_API void  (lua_concat) (lua_State *L, int n);
00241 
00242 LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
00243 LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
00244 
00245 
00246 
00247 /* 
00248 ** ===============================================================
00249 ** some useful macros
00250 ** ===============================================================
00251 */
00252 
00253 #define lua_pop(L,n)    lua_settop(L, -(n)-1)
00254 
00255 #define lua_newtable(L)   lua_createtable(L, 0, 0)
00256 
00257 #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
00258 
00259 #define lua_pushcfunction(L,f)  lua_pushcclosure(L, (f), 0)
00260 
00261 #define lua_strlen(L,i)   lua_objlen(L, (i))
00262 
00263 #define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
00264 #define lua_istable(L,n)  (lua_type(L, (n)) == LUA_TTABLE)
00265 #define lua_islightuserdata(L,n)  (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
00266 #define lua_isnil(L,n)    (lua_type(L, (n)) == LUA_TNIL)
00267 #define lua_isboolean(L,n)  (lua_type(L, (n)) == LUA_TBOOLEAN)
00268 #define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
00269 #define lua_isnone(L,n)   (lua_type(L, (n)) == LUA_TNONE)
00270 #define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
00271 
00272 #define lua_pushliteral(L, s) \
00273   lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
00274 
00275 #define lua_setglobal(L,s)  lua_setfield(L, LUA_GLOBALSINDEX, (s))
00276 #define lua_getglobal(L,s)  lua_getfield(L, LUA_GLOBALSINDEX, (s))
00277 
00278 #define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
00279 
00280 
00281 
00282 /*
00283 ** compatibility macros and functions
00284 */
00285 
00286 #define lua_open()  luaL_newstate()
00287 
00288 #define lua_getregistry(L)  lua_pushvalue(L, LUA_REGISTRYINDEX)
00289 
00290 #define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0)
00291 
00292 #define lua_Chunkreader   lua_Reader
00293 #define lua_Chunkwriter   lua_Writer
00294 
00295 
00296 /* hack */
00297 LUA_API void lua_setlevel (lua_State *from, lua_State *to);
00298 
00299 
00300 /*
00301 ** {======================================================================
00302 ** Debug API
00303 ** =======================================================================
00304 */
00305 
00306 
00307 /*
00308 ** Event codes
00309 */
00310 #define LUA_HOOKCALL  0
00311 #define LUA_HOOKRET 1
00312 #define LUA_HOOKLINE  2
00313 #define LUA_HOOKCOUNT 3
00314 #define LUA_HOOKTAILRET 4
00315 
00316 
00317 /*
00318 ** Event masks
00319 */
00320 #define LUA_MASKCALL  (1 << LUA_HOOKCALL)
00321 #define LUA_MASKRET (1 << LUA_HOOKRET)
00322 #define LUA_MASKLINE  (1 << LUA_HOOKLINE)
00323 #define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
00324 
00325 typedef struct lua_Debug lua_Debug;  /* activation record */
00326 
00327 
00328 /* Functions to be called by the debuger in specific events */
00329 typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
00330 
00331 
00332 LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);
00333 LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
00334 LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
00335 LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
00336 LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);
00337 LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);
00338 
00339 LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
00340 LUA_API lua_Hook lua_gethook (lua_State *L);
00341 LUA_API int lua_gethookmask (lua_State *L);
00342 LUA_API int lua_gethookcount (lua_State *L);
00343 
00344 
00345 struct lua_Debug {
00346   int event;
00347   const char *name; /* (n) */
00348   const char *namewhat; /* (n) `global', `local', `field', `method' */
00349   const char *what; /* (S) `Lua', `C', `main', `tail' */
00350   const char *source; /* (S) */
00351   int currentline;  /* (l) */
00352   int nups;   /* (u) number of upvalues */
00353   int linedefined;  /* (S) */
00354   int lastlinedefined;  /* (S) */
00355   char short_src[LUA_IDSIZE]; /* (S) */
00356   /* private part */
00357   int i_ci;  /* active function */
00358 };
00359 
00360 LUA_API void *active_ctx(lua_State *L);
00361 LUA_API void active_register(lua_State *L, void *ctx);
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 #endif

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:54 2011 by Doxygen 1.6.1