]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/Include/Lua/lauxlib.h
AppPkg: Add the Lua interpreter and library.
[mirror_edk2.git] / StdLib / Include / Lua / lauxlib.h
CommitLineData
16a5fed6 1/*\r
2** $Id: lauxlib.h,v 1.120.1.1 2013/04/12 18:48:47 roberto Exp $\r
3** Auxiliary functions for building Lua libraries\r
4** See Copyright Notice in lua.h\r
5*/\r
6\r
7\r
8#ifndef lauxlib_h\r
9#define lauxlib_h\r
10\r
11\r
12#include <stddef.h>\r
13#include <stdio.h>\r
14\r
15#include <Lua/lua.h>\r
16\r
17\r
18\r
19/* extra error code for `luaL_load' */\r
20#define LUA_ERRFILE (LUA_ERRERR+1)\r
21\r
22\r
23typedef struct luaL_Reg {\r
24 const char *name;\r
25 lua_CFunction func;\r
26} luaL_Reg;\r
27\r
28\r
29LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver);\r
30#define luaL_checkversion(L) luaL_checkversion_(L, LUA_VERSION_NUM)\r
31\r
32LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);\r
33LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);\r
34LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);\r
35LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);\r
36LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,\r
37 size_t *l);\r
38LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,\r
39 const char *def, size_t *l);\r
40LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg);\r
41LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def);\r
42\r
43LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);\r
44LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,\r
45 lua_Integer def);\r
46LUALIB_API lua_Unsigned (luaL_checkunsigned) (lua_State *L, int numArg);\r
47LUALIB_API lua_Unsigned (luaL_optunsigned) (lua_State *L, int numArg,\r
48 lua_Unsigned def);\r
49\r
50LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);\r
51LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);\r
52LUALIB_API void (luaL_checkany) (lua_State *L, int narg);\r
53\r
54LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);\r
55LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname);\r
56LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);\r
57LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);\r
58\r
59LUALIB_API void (luaL_where) (lua_State *L, int lvl);\r
60LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);\r
61\r
62LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,\r
63 const char *const lst[]);\r
64\r
65LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);\r
66LUALIB_API int (luaL_execresult) (lua_State *L, int stat);\r
67\r
68/* pre-defined references */\r
69#define LUA_NOREF (-2)\r
70#define LUA_REFNIL (-1)\r
71\r
72LUALIB_API int (luaL_ref) (lua_State *L, int t);\r
73LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);\r
74\r
75LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,\r
76 const char *mode);\r
77\r
78#define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL)\r
79\r
80LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,\r
81 const char *name, const char *mode);\r
82LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);\r
83\r
84LUALIB_API lua_State *(luaL_newstate) (void);\r
85\r
86LUALIB_API int (luaL_len) (lua_State *L, int idx);\r
87\r
88LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,\r
89 const char *r);\r
90\r
91LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);\r
92\r
93LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);\r
94\r
95LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,\r
96 const char *msg, int level);\r
97\r
98LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,\r
99 lua_CFunction openf, int glb);\r
100\r
101/*\r
102** ===============================================================\r
103** some useful macros\r
104** ===============================================================\r
105*/\r
106\r
107\r
108#define luaL_newlibtable(L,l) \\r
109 lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)\r
110\r
111#define luaL_newlib(L,l) (luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))\r
112\r
113#define luaL_argcheck(L, cond,numarg,extramsg) \\r
114 ((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))\r
115#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))\r
116#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))\r
117#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))\r
118#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))\r
119#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))\r
120#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))\r
121\r
122#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))\r
123\r
124#define luaL_dofile(L, fn) \\r
125 (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))\r
126\r
127#define luaL_dostring(L, s) \\r
128 (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))\r
129\r
130#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))\r
131\r
132#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))\r
133\r
134#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)\r
135\r
136\r
137/*\r
138** {======================================================\r
139** Generic Buffer manipulation\r
140** =======================================================\r
141*/\r
142\r
143typedef struct luaL_Buffer {\r
144 char *b; /* buffer address */\r
145 size_t size; /* buffer size */\r
146 size_t n; /* number of characters in buffer */\r
147 lua_State *L;\r
148 char initb[LUAL_BUFFERSIZE]; /* initial buffer */\r
149} luaL_Buffer;\r
150\r
151\r
152#define luaL_addchar(B,c) \\r
153 ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \\r
154 ((B)->b[(B)->n++] = (c)))\r
155\r
156#define luaL_addsize(B,s) ((B)->n += (s))\r
157\r
158LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);\r
159LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);\r
160LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);\r
161LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);\r
162LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);\r
163LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);\r
164LUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz);\r
165LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);\r
166\r
167#define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE)\r
168\r
169/* }====================================================== */\r
170\r
171\r
172\r
173/*\r
174** {======================================================\r
175** File handles for IO library\r
176** =======================================================\r
177*/\r
178\r
179/*\r
180** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and\r
181** initial structure 'luaL_Stream' (it may contain other fields\r
182** after that initial structure).\r
183*/\r
184\r
185#define LUA_FILEHANDLE "FILE*"\r
186\r
187\r
188typedef struct luaL_Stream {\r
189 FILE *f; /* stream (NULL for incompletely created streams) */\r
190 lua_CFunction closef; /* to close stream (NULL for closed streams) */\r
191} luaL_Stream;\r
192\r
193/* }====================================================== */\r
194\r
195\r
196\r
197/* compatibility with old module system */\r
198#if defined(LUA_COMPAT_MODULE)\r
199\r
200LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,\r
201 int sizehint);\r
202LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,\r
203 const luaL_Reg *l, int nup);\r
204\r
205#define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0))\r
206\r
207#endif\r
208\r
209\r
210#endif\r
211\r
212\r