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