annotate src/lua/lua.h @ 190:9a7a46c4aa1b

extending functionality of support namespaces in prepreation of give-pokemon
author Robert McIntyre <rlm@mit.edu>
date Thu, 22 Mar 2012 16:34:10 -0500
parents 27763b933818
children
rev   line source
rlm@1 1 /*
rlm@1 2 ** $Id: lua.h,v 1.218.1.5 2008/08/06 13:30:12 roberto Exp $
rlm@1 3 ** Lua - An Extensible Extension Language
rlm@1 4 ** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
rlm@1 5 ** See Copyright Notice at the end of this file
rlm@1 6 */
rlm@1 7
rlm@1 8
rlm@1 9 #ifndef lua_h
rlm@1 10 #define lua_h
rlm@1 11
rlm@1 12 #include <stdarg.h>
rlm@1 13 #include <stddef.h>
rlm@1 14
rlm@1 15
rlm@1 16 #include "luaconf.h"
rlm@1 17
rlm@1 18
rlm@1 19 #define LUA_VERSION "Lua 5.1"
rlm@1 20 #define LUA_RELEASE "Lua 5.1.4"
rlm@1 21 #define LUA_VERSION_NUM 501
rlm@1 22 #define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio"
rlm@1 23 #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
rlm@1 24
rlm@1 25
rlm@1 26 /* mark for precompiled code (`<esc>Lua') */
rlm@1 27 #define LUA_SIGNATURE "\033Lua"
rlm@1 28
rlm@1 29 /* option for multiple returns in `lua_pcall' and `lua_call' */
rlm@1 30 #define LUA_MULTRET (-1)
rlm@1 31
rlm@1 32
rlm@1 33 /*
rlm@1 34 ** pseudo-indices
rlm@1 35 */
rlm@1 36 #define LUA_REGISTRYINDEX (-10000)
rlm@1 37 #define LUA_ENVIRONINDEX (-10001)
rlm@1 38 #define LUA_GLOBALSINDEX (-10002)
rlm@1 39 #define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i))
rlm@1 40
rlm@1 41
rlm@1 42 /* thread status; 0 is OK */
rlm@1 43 #define LUA_YIELD 1
rlm@1 44 #define LUA_ERRRUN 2
rlm@1 45 #define LUA_ERRSYNTAX 3
rlm@1 46 #define LUA_ERRMEM 4
rlm@1 47 #define LUA_ERRERR 5
rlm@1 48
rlm@1 49
rlm@1 50 typedef struct lua_State lua_State;
rlm@1 51
rlm@1 52 typedef int (*lua_CFunction) (lua_State *L);
rlm@1 53
rlm@1 54
rlm@1 55 /*
rlm@1 56 ** functions that read/write blocks when loading/dumping Lua chunks
rlm@1 57 */
rlm@1 58 typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
rlm@1 59
rlm@1 60 typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);
rlm@1 61
rlm@1 62
rlm@1 63 /*
rlm@1 64 ** prototype for memory-allocation functions
rlm@1 65 */
rlm@1 66 typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
rlm@1 67
rlm@1 68
rlm@1 69 /*
rlm@1 70 ** basic types
rlm@1 71 */
rlm@1 72 #define LUA_TNONE (-1)
rlm@1 73
rlm@1 74 #define LUA_TNIL 0
rlm@1 75 #define LUA_TBOOLEAN 1
rlm@1 76 #define LUA_TLIGHTUSERDATA 2
rlm@1 77 #define LUA_TNUMBER 3
rlm@1 78 #define LUA_TSTRING 4
rlm@1 79 #define LUA_TTABLE 5
rlm@1 80 #define LUA_TFUNCTION 6
rlm@1 81 #define LUA_TUSERDATA 7
rlm@1 82 #define LUA_TTHREAD 8
rlm@1 83
rlm@1 84
rlm@1 85
rlm@1 86 /* minimum Lua stack available to a C function */
rlm@1 87 #define LUA_MINSTACK 20
rlm@1 88
rlm@1 89
rlm@1 90 /*
rlm@1 91 ** generic extra include file
rlm@1 92 */
rlm@1 93 #if defined(LUA_USER_H)
rlm@1 94 #include LUA_USER_H
rlm@1 95 #endif
rlm@1 96
rlm@1 97
rlm@1 98 /* type of numbers in Lua */
rlm@1 99 typedef LUA_NUMBER lua_Number;
rlm@1 100
rlm@1 101
rlm@1 102 /* type for integer functions */
rlm@1 103 typedef LUA_INTEGER lua_Integer;
rlm@1 104
rlm@1 105
rlm@1 106
rlm@1 107 /*
rlm@1 108 ** state manipulation
rlm@1 109 */
rlm@1 110 LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
rlm@1 111 LUA_API void (lua_close) (lua_State *L);
rlm@1 112 LUA_API lua_State *(lua_newthread) (lua_State *L);
rlm@1 113
rlm@1 114 LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
rlm@1 115
rlm@1 116
rlm@1 117 /*
rlm@1 118 ** basic stack manipulation
rlm@1 119 */
rlm@1 120 LUA_API int (lua_gettop) (lua_State *L);
rlm@1 121 LUA_API void (lua_settop) (lua_State *L, int idx);
rlm@1 122 LUA_API void (lua_pushvalue) (lua_State *L, int idx);
rlm@1 123 LUA_API void (lua_remove) (lua_State *L, int idx);
rlm@1 124 LUA_API void (lua_insert) (lua_State *L, int idx);
rlm@1 125 LUA_API void (lua_replace) (lua_State *L, int idx);
rlm@1 126 LUA_API int (lua_checkstack) (lua_State *L, int sz);
rlm@1 127
rlm@1 128 LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
rlm@1 129
rlm@1 130
rlm@1 131 /*
rlm@1 132 ** access functions (stack -> C)
rlm@1 133 */
rlm@1 134
rlm@1 135 LUA_API int (lua_isnumber) (lua_State *L, int idx);
rlm@1 136 LUA_API int (lua_isstring) (lua_State *L, int idx);
rlm@1 137 LUA_API int (lua_iscfunction) (lua_State *L, int idx);
rlm@1 138 LUA_API int (lua_isuserdata) (lua_State *L, int idx);
rlm@1 139 LUA_API int (lua_type) (lua_State *L, int idx);
rlm@1 140 LUA_API const char *(lua_typename) (lua_State *L, int tp);
rlm@1 141
rlm@1 142 LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2);
rlm@1 143 LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
rlm@1 144 LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2);
rlm@1 145
rlm@1 146 LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx);
rlm@1 147 LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx);
rlm@1 148 LUA_API int (lua_toboolean) (lua_State *L, int idx);
rlm@1 149 LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
rlm@1 150 LUA_API size_t (lua_objlen) (lua_State *L, int idx);
rlm@1 151 LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
rlm@1 152 LUA_API void *(lua_touserdata) (lua_State *L, int idx);
rlm@1 153 LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
rlm@1 154 LUA_API const void *(lua_topointer) (lua_State *L, int idx);
rlm@1 155
rlm@1 156
rlm@1 157 /*
rlm@1 158 ** push functions (C -> stack)
rlm@1 159 */
rlm@1 160 LUA_API void (lua_pushnil) (lua_State *L);
rlm@1 161 LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
rlm@1 162 LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
rlm@1 163 LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l);
rlm@1 164 LUA_API void (lua_pushstring) (lua_State *L, const char *s);
rlm@1 165 LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
rlm@1 166 va_list argp);
rlm@1 167 LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
rlm@1 168 LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
rlm@1 169 LUA_API void (lua_pushboolean) (lua_State *L, int b);
rlm@1 170 LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
rlm@1 171 LUA_API int (lua_pushthread) (lua_State *L);
rlm@1 172
rlm@1 173
rlm@1 174 /*
rlm@1 175 ** get functions (Lua -> stack)
rlm@1 176 */
rlm@1 177 LUA_API void (lua_gettable) (lua_State *L, int idx);
rlm@1 178 LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k);
rlm@1 179 LUA_API void (lua_rawget) (lua_State *L, int idx);
rlm@1 180 LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n);
rlm@1 181 LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
rlm@1 182 LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
rlm@1 183 LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
rlm@1 184 LUA_API void (lua_getfenv) (lua_State *L, int idx);
rlm@1 185
rlm@1 186
rlm@1 187 /*
rlm@1 188 ** set functions (stack -> Lua)
rlm@1 189 */
rlm@1 190 LUA_API void (lua_settable) (lua_State *L, int idx);
rlm@1 191 LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
rlm@1 192 LUA_API void (lua_rawset) (lua_State *L, int idx);
rlm@1 193 LUA_API void (lua_rawseti) (lua_State *L, int idx, int n);
rlm@1 194 LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
rlm@1 195 LUA_API int (lua_setfenv) (lua_State *L, int idx);
rlm@1 196
rlm@1 197
rlm@1 198 /*
rlm@1 199 ** `load' and `call' functions (load and run Lua code)
rlm@1 200 */
rlm@1 201 LUA_API void (lua_call) (lua_State *L, int nargs, int nresults);
rlm@1 202 LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
rlm@1 203 LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);
rlm@1 204 LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
rlm@1 205 const char *chunkname);
rlm@1 206
rlm@1 207 LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
rlm@1 208
rlm@1 209
rlm@1 210 /*
rlm@1 211 ** coroutine functions
rlm@1 212 */
rlm@1 213 LUA_API int (lua_yield) (lua_State *L, int nresults);
rlm@1 214 LUA_API int (lua_resume) (lua_State *L, int narg);
rlm@1 215 LUA_API int (lua_status) (lua_State *L);
rlm@1 216
rlm@1 217 /*
rlm@1 218 ** garbage-collection function and options
rlm@1 219 */
rlm@1 220
rlm@1 221 #define LUA_GCSTOP 0
rlm@1 222 #define LUA_GCRESTART 1
rlm@1 223 #define LUA_GCCOLLECT 2
rlm@1 224 #define LUA_GCCOUNT 3
rlm@1 225 #define LUA_GCCOUNTB 4
rlm@1 226 #define LUA_GCSTEP 5
rlm@1 227 #define LUA_GCSETPAUSE 6
rlm@1 228 #define LUA_GCSETSTEPMUL 7
rlm@1 229
rlm@1 230 LUA_API int (lua_gc) (lua_State *L, int what, int data);
rlm@1 231
rlm@1 232
rlm@1 233 /*
rlm@1 234 ** miscellaneous functions
rlm@1 235 */
rlm@1 236
rlm@1 237 LUA_API int (lua_error) (lua_State *L);
rlm@1 238
rlm@1 239 LUA_API int (lua_next) (lua_State *L, int idx);
rlm@1 240
rlm@1 241 LUA_API void (lua_concat) (lua_State *L, int n);
rlm@1 242
rlm@1 243 LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
rlm@1 244 LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
rlm@1 245
rlm@1 246
rlm@1 247
rlm@1 248 /*
rlm@1 249 ** ===============================================================
rlm@1 250 ** some useful macros
rlm@1 251 ** ===============================================================
rlm@1 252 */
rlm@1 253
rlm@1 254 #define lua_pop(L,n) lua_settop(L, -(n)-1)
rlm@1 255
rlm@1 256 #define lua_newtable(L) lua_createtable(L, 0, 0)
rlm@1 257
rlm@1 258 #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
rlm@1 259
rlm@1 260 #define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
rlm@1 261
rlm@1 262 #define lua_strlen(L,i) lua_objlen(L, (i))
rlm@1 263
rlm@1 264 #define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
rlm@1 265 #define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
rlm@1 266 #define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
rlm@1 267 #define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
rlm@1 268 #define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
rlm@1 269 #define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
rlm@1 270 #define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
rlm@1 271 #define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
rlm@1 272
rlm@1 273 #define lua_pushliteral(L, s) \
rlm@1 274 lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
rlm@1 275
rlm@1 276 #define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s))
rlm@1 277 #define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s))
rlm@1 278
rlm@1 279 #define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
rlm@1 280
rlm@1 281
rlm@1 282
rlm@1 283 /*
rlm@1 284 ** compatibility macros and functions
rlm@1 285 */
rlm@1 286
rlm@1 287 #define lua_open() luaL_newstate()
rlm@1 288
rlm@1 289 #define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX)
rlm@1 290
rlm@1 291 #define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0)
rlm@1 292
rlm@1 293 #define lua_Chunkreader lua_Reader
rlm@1 294 #define lua_Chunkwriter lua_Writer
rlm@1 295
rlm@1 296
rlm@1 297 /* hack */
rlm@1 298 LUA_API void lua_setlevel (lua_State *from, lua_State *to);
rlm@1 299
rlm@1 300
rlm@1 301 /*
rlm@1 302 ** {======================================================================
rlm@1 303 ** Debug API
rlm@1 304 ** =======================================================================
rlm@1 305 */
rlm@1 306
rlm@1 307
rlm@1 308 /*
rlm@1 309 ** Event codes
rlm@1 310 */
rlm@1 311 #define LUA_HOOKCALL 0
rlm@1 312 #define LUA_HOOKRET 1
rlm@1 313 #define LUA_HOOKLINE 2
rlm@1 314 #define LUA_HOOKCOUNT 3
rlm@1 315 #define LUA_HOOKTAILRET 4
rlm@1 316
rlm@1 317
rlm@1 318 /*
rlm@1 319 ** Event masks
rlm@1 320 */
rlm@1 321 #define LUA_MASKCALL (1 << LUA_HOOKCALL)
rlm@1 322 #define LUA_MASKRET (1 << LUA_HOOKRET)
rlm@1 323 #define LUA_MASKLINE (1 << LUA_HOOKLINE)
rlm@1 324 #define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
rlm@1 325
rlm@1 326 typedef struct lua_Debug lua_Debug; /* activation record */
rlm@1 327
rlm@1 328
rlm@1 329 /* Functions to be called by the debuger in specific events */
rlm@1 330 typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
rlm@1 331
rlm@1 332
rlm@1 333 LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);
rlm@1 334 LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
rlm@1 335 LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
rlm@1 336 LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
rlm@1 337 LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);
rlm@1 338 LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);
rlm@1 339
rlm@1 340 LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
rlm@1 341 LUA_API lua_Hook lua_gethook (lua_State *L);
rlm@1 342 LUA_API int lua_gethookmask (lua_State *L);
rlm@1 343 LUA_API int lua_gethookcount (lua_State *L);
rlm@1 344
rlm@1 345
rlm@1 346 struct lua_Debug {
rlm@1 347 int event;
rlm@1 348 const char *name; /* (n) */
rlm@1 349 const char *namewhat; /* (n) `global', `local', `field', `method' */
rlm@1 350 const char *what; /* (S) `Lua', `C', `main', `tail' */
rlm@1 351 const char *source; /* (S) */
rlm@1 352 int currentline; /* (l) */
rlm@1 353 int nups; /* (u) number of upvalues */
rlm@1 354 int linedefined; /* (S) */
rlm@1 355 int lastlinedefined; /* (S) */
rlm@1 356 char short_src[LUA_IDSIZE]; /* (S) */
rlm@1 357 /* private part */
rlm@1 358 int i_ci; /* active function */
rlm@1 359 };
rlm@1 360
rlm@1 361 /* }====================================================================== */
rlm@1 362
rlm@1 363
rlm@1 364 /******************************************************************************
rlm@1 365 * Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved.
rlm@1 366 *
rlm@1 367 * Permission is hereby granted, free of charge, to any person obtaining
rlm@1 368 * a copy of this software and associated documentation files (the
rlm@1 369 * "Software"), to deal in the Software without restriction, including
rlm@1 370 * without limitation the rights to use, copy, modify, merge, publish,
rlm@1 371 * distribute, sublicense, and/or sell copies of the Software, and to
rlm@1 372 * permit persons to whom the Software is furnished to do so, subject to
rlm@1 373 * the following conditions:
rlm@1 374 *
rlm@1 375 * The above copyright notice and this permission notice shall be
rlm@1 376 * included in all copies or substantial portions of the Software.
rlm@1 377 *
rlm@1 378 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
rlm@1 379 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
rlm@1 380 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
rlm@1 381 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
rlm@1 382 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
rlm@1 383 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
rlm@1 384 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
rlm@1 385 ******************************************************************************/
rlm@1 386
rlm@1 387
rlm@1 388 #endif