Lua 5.1.4: lua.h
This is the public interface to the core Lua library.
L0001
L0007
L0008
L0009 #ifndef lua_h
L0010 #define lua_h
L0011
L0012 #include <stdarg.h>
L0013 #include <stddef.h>
L0014
L0015
L0016 #include "luaconf.h"
L0017
L0018
L0019 #define LUA_VERSION "Lua 5.1"
L0020 #define LUA_RELEASE "Lua 5.1.4"
L0021 #define LUA_VERSION_NUM 501
This is the number exposed by lua_version().
Note: 502 mean "5.2". 501 means "5.1"
L0022 #define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio"
L0023 #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
L0024
L0025
L0026
L0027 #define LUA_SIGNATURE "\033Lua"
Lua bytecode always starts with a signature consisting
of these bytes. Both Lua 5.1 and 5.2 start with this
signature. Some functions like load() determine whether
a file is Lua source code or Lua byte code by looking
for this signature. The \033 (escape) character is not
a valid first character in Lua source code.
L0028
L0029
L0030 #define LUA_MULTRET (-1)
L0031
L0032
L0033
L0036 #define LUA_REGISTRYINDEX (-10000)
L0037 #define LUA_ENVIRONINDEX (-10001)
L0038 #define LUA_GLOBALSINDEX (-10002)
L0039 #define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i))
L0040
L0041
L0042
L0043 #define LUA_YIELD 1
L0044 #define LUA_ERRRUN 2
L0045 #define LUA_ERRSYNTAX 3
L0046 #define LUA_ERRMEM 4
L0047 #define LUA_ERRERR 5
Note: see also LUA_ERRFILE in lauxlib.h.
L0048
L0049
L0050 typedef struct lua_State lua_State;
L0051
L0052 typedef int (*lua_CFunction) (lua_State *L);
L0053
L0054
L0055
L0058 typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
L0059
L0060 typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);
L0061
L0062
L0063
L0066 typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
L0067
L0068
L0069
L0072 #define LUA_TNONE (-1)
L0073
L0074 #define LUA_TNIL 0
L0075 #define LUA_TBOOLEAN 1
L0076 #define LUA_TLIGHTUSERDATA 2
L0077 #define LUA_TNUMBER 3
L0078 #define LUA_TSTRING 4
L0079 #define LUA_TTABLE 5
L0080 #define LUA_TFUNCTION 6
L0081 #define LUA_TUSERDATA 7
L0082 #define LUA_TTHREAD 8
L0083
L0084
L0085
L0086
L0087 #define LUA_MINSTACK 20
From the reference manual:
Whenever Lua calls C, it ensures that at least
LUA_MINSTACK stack positions are available.
LUA_MINSTACK is defined as 20, so that usually
you do not have to worry about stack space
unless your code has loops pushing elements
onto the stack.
L0088
L0089
L0090
L0093 #if defined(LUA_USER_H)
L0094 #include LUA_USER_H
L0095 #endif
L0096
L0097
L0098
L0099 typedef LUA_NUMBER lua_Number;
Typically set to double on PCs.
L0100
L0101
L0102
L0103 typedef LUA_INTEGER lua_Integer;
Typically set to int (32-bit) on PCs.
L0104
L0105
L0106
L0107
L0110 LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
L0111 LUA_API void (lua_close) (lua_State *L);
L0112 LUA_API lua_State *(lua_newthread) (lua_State *L);
L0113
L0114 LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
L0115
L0116
L0117
L0120 LUA_API int (lua_gettop) (lua_State *L);
L0121 LUA_API void (lua_settop) (lua_State *L, int idx);
L0122 LUA_API void (lua_pushvalue) (lua_State *L, int idx);
L0123 LUA_API void (lua_remove) (lua_State *L, int idx);
L0124 LUA_API void (lua_insert) (lua_State *L, int idx);
L0125 LUA_API void (lua_replace) (lua_State *L, int idx);
L0126 LUA_API int (lua_checkstack) (lua_State *L, int sz);
L0127
L0128 LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
L0129
L0130
L0131
L0134
L0135 LUA_API int (lua_isnumber) (lua_State *L, int idx);
L0136 LUA_API int (lua_isstring) (lua_State *L, int idx);
L0137 LUA_API int (lua_iscfunction) (lua_State *L, int idx);
L0138 LUA_API int (lua_isuserdata) (lua_State *L, int idx);
L0139 LUA_API int (lua_type) (lua_State *L, int idx);
L0140 LUA_API const char *(lua_typename) (lua_State *L, int tp);
L0141
L0142 LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2);
L0143 LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
L0144 LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2);
L0145
L0146 LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx);
L0147 LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx);
L0148 LUA_API int (lua_toboolean) (lua_State *L, int idx);
L0149 LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
L0150 LUA_API size_t (lua_objlen) (lua_State *L, int idx);
L0151 LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
L0152 LUA_API void *(lua_touserdata) (lua_State *L, int idx);
L0153 LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
L0154 LUA_API const void *(lua_topointer) (lua_State *L, int idx);
L0155
L0156
L0157
L0160 LUA_API void (lua_pushnil) (lua_State *L);
L0161 LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
L0162 LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
L0163 LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l);
L0164 LUA_API void (lua_pushstring) (lua_State *L, const char *s);
L0165 LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
L0166 va_list argp);
L0167 LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
L0168 LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
L0169 LUA_API void (lua_pushboolean) (lua_State *L, int b);
L0170 LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
L0171 LUA_API int (lua_pushthread) (lua_State *L);
L0172
L0173
L0174
L0177 LUA_API void (lua_gettable) (lua_State *L, int idx);
L0178 LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k);
L0179 LUA_API void (lua_rawget) (lua_State *L, int idx);
L0180 LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n);
L0181 LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
L0182 LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
L0183 LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
L0184 LUA_API void (lua_getfenv) (lua_State *L, int idx);
L0185
L0186
L0187
L0190 LUA_API void (lua_settable) (lua_State *L, int idx);
L0191 LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
L0192 LUA_API void (lua_rawset) (lua_State *L, int idx);
L0193 LUA_API void (lua_rawseti) (lua_State *L, int idx, int n);
L0194 LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
L0195 LUA_API int (lua_setfenv) (lua_State *L, int idx);
L0196
L0197
L0198
L0201 LUA_API void (lua_call) (lua_State *L, int nargs, int nresults);
L0202 LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
L0203 LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);
L0204 LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
L0205 const char *chunkname);
L0206
L0207 LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
L0208
L0209
L0210
L0213 LUA_API int (lua_yield) (lua_State *L, int nresults);
L0214 LUA_API int (lua_resume) (lua_State *L, int narg);
L0215 LUA_API int (lua_status) (lua_State *L);
L0216
L0217
L0220
L0221 #define LUA_GCSTOP 0
L0222 #define LUA_GCRESTART 1
L0223 #define LUA_GCCOLLECT 2
L0224 #define LUA_GCCOUNT 3
L0225 #define LUA_GCCOUNTB 4
L0226 #define LUA_GCSTEP 5
L0227 #define LUA_GCSETPAUSE 6
L0228 #define LUA_GCSETSTEPMUL 7
L0229
L0230 LUA_API int (lua_gc) (lua_State *L, int what, int data);
L0231
L0232
L0233
L0236
L0237 LUA_API int (lua_error) (lua_State *L);
L0238
L0239 LUA_API int (lua_next) (lua_State *L, int idx);
L0240
L0241 LUA_API void (lua_concat) (lua_State *L, int n);
L0242
L0243 LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
L0244 LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
L0245
L0246
L0247
L0248
L0253
L0254 #define lua_pop(L,n) lua_settop(L, -(n)-1)
L0255
L0256 #define lua_newtable(L) lua_createtable(L, 0, 0)
L0257
L0258 #define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
L0259
L0260 #define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
L0261
L0262 #define lua_strlen(L,i) lua_objlen(L, (i))
L0263
L0264 #define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
L0265 #define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
L0266 #define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
L0267 #define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
L0268 #define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
L0269 #define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
L0270 #define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
L0271 #define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
L0272
L0273 #define lua_pushliteral(L, s) \
L0274 lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
L0275
L0276 #define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s))
L0277 #define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s))
L0278
L0279 #define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
L0280
L0281
L0282
L0283
L0286
L0287 #define lua_open() luaL_newstate()
L0288
L0289 #define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX)
L0290
L0291 #define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0)
L0292
L0293 #define lua_Chunkreader lua_Reader
L0294 #define lua_Chunkwriter lua_Writer
L0295
L0296
L0297
L0298 LUA_API void lua_setlevel (lua_State *from, lua_State *to);
L0299
L0300
L0301
L0306
L0307
L0308
L0311 #define LUA_HOOKCALL 0
L0312 #define LUA_HOOKRET 1
L0313 #define LUA_HOOKLINE 2
L0314 #define LUA_HOOKCOUNT 3
L0315 #define LUA_HOOKTAILRET 4
L0316
L0317
L0318
L0321 #define LUA_MASKCALL (1 << LUA_HOOKCALL)
L0322 #define LUA_MASKRET (1 << LUA_HOOKRET)
L0323 #define LUA_MASKLINE (1 << LUA_HOOKLINE)
L0324 #define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
L0325
L0326 typedef struct lua_Debug lua_Debug;
L0327
L0328
L0329
L0330 typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
L0331
L0332
L0333 LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);
L0334 LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
L0335 LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
L0336 LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
L0337 LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);
L0338 LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);
L0339
L0340 LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
L0341 LUA_API lua_Hook lua_gethook (lua_State *L);
L0342 LUA_API int lua_gethookmask (lua_State *L);
L0343 LUA_API int lua_gethookcount (lua_State *L);
L0344
L0345
L0346 struct lua_Debug {
L0347 int event;
L0348 const char *name;
L0349 const char *namewhat;
L0350 const char *what;
L0351 const char *source;
L0352 int currentline;
L0353 int nups;
L0354 int linedefined;
L0355 int lastlinedefined;
L0356 char short_src[LUA_IDSIZE];
L0357
L0358 int i_ci;
L0359 };
L0360
L0361
L0362
L0363
L0364
L0386
L0387
L0388 #endif
Generated by pretty.lua