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


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:09