lauxlib.h
Go to the documentation of this file.
1 /*
2 ** $Id: lauxlib.h $
3 ** Auxiliary functions for building Lua libraries
4 ** See Copyright Notice in lua.h
5 */
6 
7 
8 #ifndef lauxlib_h
9 #define lauxlib_h
10 
11 
12 #include <stddef.h>
13 #include <stdio.h>
14 
15 #include "luaconf.h"
16 #include "lua.h"
17 
18 
19 /* global table */
20 #define LUA_GNAME "_G"
21 
22 
23 typedef struct luaL_Buffer luaL_Buffer;
24 
25 
26 /* extra error code for 'luaL_loadfilex' */
27 #define LUA_ERRFILE (LUA_ERRERR+1)
28 
29 
30 /* key, in the registry, for table of loaded modules */
31 #define LUA_LOADED_TABLE "_LOADED"
32 
33 
34 /* key, in the registry, for table of preloaded loaders */
35 #define LUA_PRELOAD_TABLE "_PRELOAD"
36 
37 
38 typedef struct luaL_Reg {
39  const char *name;
41 } luaL_Reg;
42 
43 
44 #define LUAL_NUMSIZES (sizeof(lua_Integer)*16 + sizeof(lua_Number))
45 
47 #define luaL_checkversion(L) \
48  luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES)
49 
50 LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
51 LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
52 LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);
53 LUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg);
54 LUALIB_API int (luaL_typeerror) (lua_State *L, int arg, const char *tname);
55 LUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg,
56  size_t *l);
57 LUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg,
58  const char *def, size_t *l);
61 
64  lua_Integer def);
65 
66 LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
67 LUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t);
69 
70 LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
71 LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname);
72 LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);
73 LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
74 
75 LUALIB_API void (luaL_where) (lua_State *L, int lvl);
76 LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
77 
78 LUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def,
79  const char *const lst[]);
80 
81 LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);
82 LUALIB_API int (luaL_execresult) (lua_State *L, int stat);
83 
84 
85 /* predefined references */
86 #define LUA_NOREF (-2)
87 #define LUA_REFNIL (-1)
88 
89 LUALIB_API int (luaL_ref) (lua_State *L, int t);
90 LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
91 
92 LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,
93  const char *mode);
94 
95 #define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL)
96 
97 LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,
98  const char *name, const char *mode);
99 LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
100 
102 
103 LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx);
104 
105 LUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s,
106  const char *p, const char *r);
107 LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s,
108  const char *p, const char *r);
109 
110 LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
111 
112 LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);
113 
115  const char *msg, int level);
116 
117 LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
118  lua_CFunction openf, int glb);
119 
120 /*
121 ** ===============================================================
122 ** some useful macros
123 ** ===============================================================
124 */
125 
126 
127 #define luaL_newlibtable(L,l) \
128  lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
129 
130 #define luaL_newlib(L,l) \
131  (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
132 
133 #define luaL_argcheck(L, cond,arg,extramsg) \
134  ((void)(luai_likely(cond) || luaL_argerror(L, (arg), (extramsg))))
135 
136 #define luaL_argexpected(L,cond,arg,tname) \
137  ((void)(luai_likely(cond) || luaL_typeerror(L, (arg), (tname))))
138 
139 #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
140 #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
141 
142 #define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
143 
144 #define luaL_dofile(L, fn) \
145  (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
146 
147 #define luaL_dostring(L, s) \
148  (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
149 
150 #define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
151 
152 #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
153 
154 #define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)
155 
156 
157 /* push the value used to represent failure/error */
158 #define luaL_pushfail(L) lua_pushnil(L)
159 
160 
161 /*
162 ** Internal assertions for in-house debugging
163 */
164 #if !defined(lua_assert)
165 
166 #if defined LUAI_ASSERT
167  #include <assert.h>
168  #define lua_assert(c) assert(c)
169 #else
170  #define lua_assert(c) ((void)0)
171 #endif
172 
173 #endif
174 
175 
176 
177 /*
178 ** {======================================================
179 ** Generic Buffer manipulation
180 ** =======================================================
181 */
182 
183 struct luaL_Buffer {
184  char *b; /* buffer address */
185  size_t size; /* buffer size */
186  size_t n; /* number of characters in buffer */
188  union {
189  LUAI_MAXALIGN; /* ensure maximum alignment for buffer */
190  char b[LUAL_BUFFERSIZE]; /* initial buffer */
191  } init;
192 };
193 
194 
195 #define luaL_bufflen(bf) ((bf)->n)
196 #define luaL_buffaddr(bf) ((bf)->b)
197 
198 
199 #define luaL_addchar(B,c) \
200  ((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \
201  ((B)->b[(B)->n++] = (c)))
202 
203 #define luaL_addsize(B,s) ((B)->n += (s))
204 
205 #define luaL_buffsub(B,s) ((B)->n -= (s))
206 
208 LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);
209 LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
210 LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);
214 LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);
215 
216 #define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE)
217 
218 /* }====================================================== */
219 
220 
221 
222 /*
223 ** {======================================================
224 ** File handles for IO library
225 ** =======================================================
226 */
227 
228 /*
229 ** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and
230 ** initial structure 'luaL_Stream' (it may contain other fields
231 ** after that initial structure).
232 */
233 
234 #define LUA_FILEHANDLE "FILE*"
235 
236 
237 typedef struct luaL_Stream {
238  FILE *f; /* stream (NULL for incompletely created streams) */
239  lua_CFunction closef; /* to close stream (NULL for closed streams) */
240 } luaL_Stream;
241 
242 /* }====================================================== */
243 
244 /*
245 ** {==================================================================
246 ** "Abstraction Layer" for basic report of messages and errors
247 ** ===================================================================
248 */
249 
250 /* print a string */
251 #if !defined(lua_writestring)
252 #define lua_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
253 #endif
254 
255 /* print a newline and flush the output */
256 #if !defined(lua_writeline)
257 #define lua_writeline() (lua_writestring("\n", 1), fflush(stdout))
258 #endif
259 
260 /* print an error message */
261 #if !defined(lua_writestringerror)
262 #define lua_writestringerror(s,p) \
263  (fprintf(stderr, (s), (p)), fflush(stderr))
264 #endif
265 
266 /* }================================================================== */
267 
268 
269 /*
270 ** {============================================================
271 ** Compatibility with deprecated conversions
272 ** =============================================================
273 */
274 #if defined(LUA_COMPAT_APIINTCASTS)
275 
276 #define luaL_checkunsigned(L,a) ((lua_Unsigned)luaL_checkinteger(L,a))
277 #define luaL_optunsigned(L,a,d) \
278  ((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d)))
279 
280 #define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
281 #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
282 
283 #define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
284 #define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
285 
286 #endif
287 /* }============================================================ */
288 
289 
290 
291 #endif
292 
293 
luaL_checkversion_
LUALIB_API void() luaL_checkversion_(lua_State *L, lua_Number ver, size_t sz)
Definition: lauxlib.c:1097
luaL_addlstring
LUALIB_API void() luaL_addlstring(luaL_Buffer *B, const char *s, size_t l)
Definition: lauxlib.c:579
luaL_checkinteger
LUALIB_API lua_Integer() luaL_checkinteger(lua_State *L, int arg)
Definition: lauxlib.c:442
luaL_fileresult
LUALIB_API int() luaL_fileresult(lua_State *L, int stat, const char *fname)
Definition: lauxlib.c:245
luaL_requiref
LUALIB_API void() luaL_requiref(lua_State *L, const char *modname, lua_CFunction openf, int glb)
Definition: lauxlib.c:967
luaL_Buffer::L
lua_State * L
Definition: lauxlib.h:187
luaL_Reg
Definition: lauxlib.h:38
luaconf.h
luaL_Reg
struct luaL_Reg luaL_Reg
luaL_setmetatable
LUALIB_API void() luaL_setmetatable(lua_State *L, const char *tname)
Definition: lauxlib.c:324
luaL_optnumber
LUALIB_API lua_Number() luaL_optnumber(lua_State *L, int arg, lua_Number def)
Definition: lauxlib.c:429
s
XmlRpcServer s
luaL_Buffer::b
char * b
Definition: lauxlib.h:184
luaL_checklstring
const LUALIB_API char *() luaL_checklstring(lua_State *L, int arg, size_t *l)
Definition: lauxlib.c:402
luaL_gsub
const LUALIB_API char *() luaL_gsub(lua_State *L, const char *s, const char *p, const char *r)
Definition: lauxlib.c:1000
luaL_checkany
LUALIB_API void() luaL_checkany(lua_State *L, int arg)
Definition: lauxlib.c:396
luaL_where
LUALIB_API void() luaL_where(lua_State *L, int lvl)
Definition: lauxlib.c:216
arg
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Definition: core.h:1875
lua_Number
LUA_NUMBER lua_Number
Definition: lua.h:90
luaL_Stream
Definition: lauxlib.h:237
luaL_setfuncs
LUALIB_API void() luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
Definition: lauxlib.c:926
mqtt_test_proto.msg
msg
Definition: mqtt_test_proto.py:43
luaL_checkoption
LUALIB_API int() luaL_checkoption(lua_State *L, int arg, const char *def, const char *const lst[])
Definition: lauxlib.c:360
luaL_execresult
LUALIB_API int() luaL_execresult(lua_State *L, int stat)
Definition: lauxlib.c:285
luaL_unref
LUALIB_API void() luaL_unref(lua_State *L, int t, int ref)
Definition: lauxlib.c:688
luaL_Buffer::n
size_t n
Definition: lauxlib.h:186
luaL_Buffer::size
size_t size
Definition: lauxlib.h:185
luaL_traceback
LUALIB_API void() luaL_traceback(lua_State *L, lua_State *L1, const char *msg, int level)
Definition: lauxlib.c:131
luaL_ref
LUALIB_API int() luaL_ref(lua_State *L, int t)
Definition: lauxlib.c:660
lua.h
luaL_newstate
LUALIB_API lua_State *() luaL_newstate(void)
Definition: lauxlib.c:1087
luaL_addgsub
LUALIB_API void luaL_addgsub(luaL_Buffer *b, const char *s, const char *p, const char *r)
Definition: lauxlib.c:987
LUAL_BUFFERSIZE
#define LUAL_BUFFERSIZE
Definition: luaconf.h:763
luaL_loadstring
LUALIB_API int() luaL_loadstring(lua_State *L, const char *s)
Definition: lauxlib.c:837
luaL_checktype
LUALIB_API void() luaL_checktype(lua_State *L, int arg, int t)
Definition: lauxlib.c:390
luaL_optlstring
const LUALIB_API char *() luaL_optlstring(lua_State *L, int arg, const char *def, size_t *l)
Definition: lauxlib.c:409
lua_State
Definition: lstate.h:304
luaL_addstring
LUALIB_API void() luaL_addstring(luaL_Buffer *B, const char *s)
Definition: lauxlib.c:588
luaL_callmeta
LUALIB_API int() luaL_callmeta(lua_State *L, int obj, const char *e)
Definition: lauxlib.c:861
luaL_len
LUALIB_API lua_Integer() luaL_len(lua_State *L, int idx)
Definition: lauxlib.c:871
luaL_Reg::func
lua_CFunction func
Definition: lauxlib.h:40
nlohmann::detail::void
j template void())
Definition: json.hpp:4061
luaL_loadfilex
LUALIB_API int() luaL_loadfilex(lua_State *L, const char *filename, const char *mode)
Definition: lauxlib.c:776
luaL_buffinitsize
LUALIB_API char *() luaL_buffinitsize(lua_State *L, luaL_Buffer *B, size_t sz)
Definition: lauxlib.c:638
lua_Integer
LUA_INTEGER lua_Integer
Definition: lua.h:94
luaL_pushresultsize
LUALIB_API void() luaL_pushresultsize(luaL_Buffer *B, size_t sz)
Definition: lauxlib.c:603
luaL_Reg::name
const char * name
Definition: lauxlib.h:39
luaL_pushresult
LUALIB_API void() luaL_pushresult(luaL_Buffer *B)
Definition: lauxlib.c:593
luaL_prepbuffsize
LUALIB_API char *() luaL_prepbuffsize(luaL_Buffer *B, size_t sz)
Definition: lauxlib.c:574
luaL_testudata
LUALIB_API void *() luaL_testudata(lua_State *L, int ud, const char *tname)
Definition: lauxlib.c:330
udp_client.int
int
Definition: udp_client.py:11
luaL_Buffer
Definition: lauxlib.h:183
luaL_error
LUALIB_API int() luaL_error(lua_State *L, const char *fmt,...)
Definition: lauxlib.c:234
luaL_buffinit
LUALIB_API void() luaL_buffinit(lua_State *L, luaL_Buffer *B)
Definition: lauxlib.c:629
luaL_Buffer::init
union luaL_Buffer::@0 init
luaL_optinteger
LUALIB_API lua_Integer() luaL_optinteger(lua_State *L, int arg, lua_Integer def)
Definition: lauxlib.c:452
B
#define B(name, bit)
lua_CFunction
int(* lua_CFunction)(lua_State *L)
Definition: lua.h:106
luaL_Stream::closef
lua_CFunction closef
Definition: lauxlib.h:239
luaL_getsubtable
LUALIB_API int() luaL_getsubtable(lua_State *L, int idx, const char *fname)
Definition: lauxlib.c:947
luaL_Stream::f
FILE * f
Definition: lauxlib.h:238
luaL_checkudata
LUALIB_API void *() luaL_checkudata(lua_State *L, int ud, const char *tname)
Definition: lauxlib.c:345
luaL_loadbufferx
LUALIB_API int() luaL_loadbufferx(lua_State *L, const char *buff, size_t sz, const char *name, const char *mode)
Definition: lauxlib.c:828
luaL_checknumber
LUALIB_API lua_Number() luaL_checknumber(lua_State *L, int arg)
Definition: lauxlib.c:420
assert.h
luaL_newmetatable
LUALIB_API int() luaL_newmetatable(lua_State *L, const char *tname)
Definition: lauxlib.c:311
luaL_Stream
struct luaL_Stream luaL_Stream
luaL_checkstack
LUALIB_API void() luaL_checkstack(lua_State *L, int sz, const char *msg)
Definition: lauxlib.c:380
luaL_typeerror
LUALIB_API int() luaL_typeerror(lua_State *L, int arg, const char *tname)
Definition: lauxlib.c:193
luaL_getmetafield
LUALIB_API int() luaL_getmetafield(lua_State *L, int obj, const char *e)
Definition: lauxlib.c:845
luaL_Buffer::LUAI_MAXALIGN
LUAI_MAXALIGN
Definition: lauxlib.h:189
LUALIB_API
#define LUALIB_API
Definition: luaconf.h:290
luaL_tolstring
const LUALIB_API char *() luaL_tolstring(lua_State *L, int idx, size_t *len)
Definition: lauxlib.c:883
luaL_argerror
LUALIB_API int() luaL_argerror(lua_State *L, int arg, const char *extramsg)
Definition: lauxlib.c:175
luaL_addvalue
LUALIB_API void() luaL_addvalue(luaL_Buffer *B)
Definition: lauxlib.c:618


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:44