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

Generated by  doxygen 1.6.2