Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lbaselib.c File Reference
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"

Go to the source code of this file.

Macros

#define lbaselib_c
 
#define LUA_LIB
 
#define SPACECHARS   " \f\n\r\t\v"
 
#define RESERVEDSLOT   5
 

Functions

static int luaB_print (lua_State *L)
 
static int luaB_tonumber (lua_State *L)
 
static int luaB_error (lua_State *L)
 
static int luaB_getmetatable (lua_State *L)
 
static int luaB_setmetatable (lua_State *L)
 
static int luaB_rawequal (lua_State *L)
 
static int luaB_rawlen (lua_State *L)
 
static int luaB_rawget (lua_State *L)
 
static int luaB_rawset (lua_State *L)
 
static int luaB_collectgarbage (lua_State *L)
 
static int luaB_type (lua_State *L)
 
static int pairsmeta (lua_State *L, const char *method, int iszero, lua_CFunction iter)
 
static int luaB_next (lua_State *L)
 
static int luaB_pairs (lua_State *L)
 
static int ipairsaux (lua_State *L)
 
static int luaB_ipairs (lua_State *L)
 
static int load_aux (lua_State *L, int status, int envidx)
 
static int luaB_loadfile (lua_State *L)
 
static const char * generic_reader (lua_State *L, void *ud, size_t *size)
 
static int luaB_load (lua_State *L)
 
static int dofilecont (lua_State *L)
 
static int luaB_dofile (lua_State *L)
 
static int luaB_assert (lua_State *L)
 
static int luaB_select (lua_State *L)
 
static int finishpcall (lua_State *L, int status)
 
static int pcallcont (lua_State *L)
 
static int luaB_pcall (lua_State *L)
 
static int luaB_xpcall (lua_State *L)
 
static int luaB_tostring (lua_State *L)
 
LUAMOD_API int luaopen_base (lua_State *L)
 

Variables

static const luaL_Reg base_funcs []
 

Macro Definition Documentation

◆ lbaselib_c

#define lbaselib_c

Definition at line 14 of file lua-5.2.4/src/lbaselib.c.

◆ LUA_LIB

#define LUA_LIB

Definition at line 15 of file lua-5.2.4/src/lbaselib.c.

◆ RESERVEDSLOT

#define RESERVEDSLOT   5

Definition at line 283 of file lua-5.2.4/src/lbaselib.c.

Referenced by generic_reader(), and luaB_load().

◆ SPACECHARS

#define SPACECHARS   " \f\n\r\t\v"

Definition at line 46 of file lua-5.2.4/src/lbaselib.c.

Referenced by luaB_tonumber().

Function Documentation

◆ dofilecont()

static int dofilecont ( lua_State * L)
static

Definition at line 331 of file lua-5.2.4/src/lbaselib.c.

331 {
332 return lua_gettop(L) - 1;
333}
LUA_API int lua_gettop(lua_State *L)

References lua_gettop().

Referenced by luaB_dofile().

◆ finishpcall()

static int finishpcall ( lua_State * L,
int status )
static

Definition at line 369 of file lua-5.2.4/src/lbaselib.c.

369 {
370 if (!lua_checkstack(L, 1)) { /* no space for extra boolean? */
371 lua_settop(L, 0); /* create space for return values */
372 lua_pushboolean(L, 0);
373 lua_pushstring(L, "stack overflow");
374 return 2; /* return false, msg */
375 }
376 lua_pushboolean(L, status); /* first result (status) */
377 lua_replace(L, 1); /* put first result in first slot */
378 return lua_gettop(L);
379}
LUA_API void lua_pushstring(lua_State *L, const char *s)
LUA_API void lua_pushboolean(lua_State *L, int b)
LUA_API int lua_checkstack(lua_State *L, int size)
LUA_API void lua_settop(lua_State *L, int idx)
#define lua_replace(L, idx)

References lua_checkstack(), lua_gettop(), lua_pushboolean(), lua_pushstring(), lua_replace, and lua_settop().

Referenced by luaB_pcall(), luaB_xpcall(), and pcallcont().

◆ generic_reader()

static const char * generic_reader ( lua_State * L,
void * ud,
size_t * size )
static

Definition at line 292 of file lua-5.2.4/src/lbaselib.c.

292 {
293 (void)(ud); /* not used */
294 luaL_checkstack(L, 2, "too many nested functions");
295 lua_pushvalue(L, 1); /* get function */
296 lua_call(L, 0, 1); /* call it */
297 if (lua_isnil(L, -1)) {
298 lua_pop(L, 1); /* pop result */
299 *size = 0;
300 return NULL;
301 }
302 else if (!lua_isstring(L, -1))
303 luaL_error(L, "reader function must return a string");
304 lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */
305 return lua_tolstring(L, RESERVEDSLOT, size);
306}
#define NULL
Definition gmacros.h:924
LUA_API const char * lua_tolstring(lua_State *L, int idx, size_t *len)
LUA_API void lua_pushvalue(lua_State *L, int idx)
LUA_API int lua_isstring(lua_State *L, int idx)
LUALIB_API void luaL_checkstack(lua_State *L, int space, const char *mes)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
#define lua_isnil(L, n)
#define lua_pop(L, n)
#define RESERVEDSLOT
#define lua_call(L, n, r)

References lua_call, lua_isnil, lua_isstring(), lua_pop, lua_pushvalue(), lua_replace, lua_tolstring(), luaL_checkstack(), luaL_error(), NULL, and RESERVEDSLOT.

Referenced by luaB_load().

◆ ipairsaux()

static int ipairsaux ( lua_State * L)
static

Definition at line 230 of file lua-5.2.4/src/lbaselib.c.

230 {
231 int i = luaL_checkint(L, 2);
233 i++; /* next value */
234 lua_pushinteger(L, i);
235 lua_rawgeti(L, 1, i);
236 return (lua_isnil(L, -1)) ? 1 : 2;
237}
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
LUA_API void lua_rawgeti(lua_State *L, int idx, int n)
LUALIB_API void luaL_checktype(lua_State *L, int narg, int t)
#define luaL_checkint(L, n)
#define LUA_TTABLE

References lua_isnil, lua_pushinteger(), lua_rawgeti(), LUA_TTABLE, luaL_checkint, and luaL_checktype().

Referenced by luaB_ipairs().

◆ load_aux()

static int load_aux ( lua_State * L,
int status,
int envidx )
static

Definition at line 245 of file lua-5.2.4/src/lbaselib.c.

245 {
246 if (status == LUA_OK) {
247 if (envidx != 0) { /* 'env' parameter? */
248 lua_pushvalue(L, envidx); /* environment for loaded function */
249 if (!lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */
250 lua_pop(L, 1); /* remove 'env' if not used by previous call */
251 }
252 return 1;
253 }
254 else { /* error (message is on top of the stack) */
255 lua_pushnil(L);
256 lua_insert(L, -2); /* put before error message */
257 return 2; /* return nil plus error message */
258 }
259}
LUA_API void lua_pushnil(lua_State *L)
LUA_API const char * lua_setupvalue(lua_State *L, int funcindex, int n)
#define LUA_OK
#define lua_insert(L, idx)

References lua_insert, LUA_OK, lua_pop, lua_pushnil(), lua_pushvalue(), and lua_setupvalue().

Referenced by luaB_load(), and luaB_loadfile().

◆ luaB_assert()

static int luaB_assert ( lua_State * L)
static

Definition at line 346 of file lua-5.2.4/src/lbaselib.c.

346 {
347 if (!lua_toboolean(L, 1))
348 return luaL_error(L, "%s", luaL_optstring(L, 2, "assertion failed!"));
349 return lua_gettop(L);
350}
LUA_API int lua_toboolean(lua_State *L, int idx)
#define luaL_optstring(L, n, d)

References lua_gettop(), lua_toboolean(), luaL_error(), and luaL_optstring.

◆ luaB_collectgarbage()

static int luaB_collectgarbage ( lua_State * L)
static

Definition at line 160 of file lua-5.2.4/src/lbaselib.c.

160 {
161 static const char *const opts[] = {"stop", "restart", "collect",
162 "count", "step", "setpause", "setstepmul",
163 "setmajorinc", "isrunning", "generational", "incremental", NULL};
164 static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
167 int o = optsnum[luaL_checkoption(L, 1, "collect", opts)];
168 int ex = luaL_optint(L, 2, 0);
169 int res = lua_gc(L, o, ex);
170 switch (o) {
171 case LUA_GCCOUNT: {
172 int b = lua_gc(L, LUA_GCCOUNTB, 0);
173 lua_pushnumber(L, res + ((lua_Number)b/1024));
174 lua_pushinteger(L, b);
175 return 2;
176 }
177 case LUA_GCSTEP: case LUA_GCISRUNNING: {
178 lua_pushboolean(L, res);
179 return 1;
180 }
181 default: {
182 lua_pushinteger(L, res);
183 return 1;
184 }
185 }
186}
LUA_API void lua_pushnumber(lua_State *L, lua_Number n)
LUA_API int lua_gc(lua_State *L, int what, int data)
LUALIB_API int luaL_checkoption(lua_State *L, int narg, const char *def, const char *const lst[])
#define luaL_optint(L, n, d)
#define LUA_GCSETPAUSE
#define LUA_GCCOUNT
#define LUA_GCCOLLECT
#define LUA_GCSTOP
#define LUA_GCRESTART
#define LUA_GCCOUNTB
#define LUA_GCSTEP
#define LUA_GCSETSTEPMUL
LUA_NUMBER lua_Number
#define LUA_GCGEN
#define LUA_GCSETMAJORINC
#define LUA_GCINC
#define LUA_GCISRUNNING

References lua_gc(), LUA_GCCOLLECT, LUA_GCCOUNT, LUA_GCCOUNTB, LUA_GCGEN, LUA_GCINC, LUA_GCISRUNNING, LUA_GCRESTART, LUA_GCSETMAJORINC, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL, LUA_GCSTEP, LUA_GCSTOP, lua_pushboolean(), lua_pushinteger(), lua_pushnumber(), luaL_checkoption(), luaL_optint, and NULL.

◆ luaB_dofile()

static int luaB_dofile ( lua_State * L)
static

Definition at line 336 of file lua-5.2.4/src/lbaselib.c.

336 {
337 const char *fname = luaL_optstring(L, 1, NULL);
338 lua_settop(L, 1);
339 if (luaL_loadfile(L, fname) != LUA_OK)
340 return lua_error(L);
342 return dofilecont(L);
343}
LUA_API int lua_error(lua_State *L)
#define LUA_MULTRET
LUA_API void lua_callk(lua_State *L, int nargs, int nresults, int ctx, lua_CFunction k)
#define luaL_loadfile(L, f)
static int dofilecont(lua_State *L)

References dofilecont(), lua_callk(), lua_error(), LUA_MULTRET, LUA_OK, lua_settop(), luaL_loadfile, luaL_optstring, and NULL.

◆ luaB_error()

static int luaB_error ( lua_State * L)
static

Definition at line 89 of file lua-5.2.4/src/lbaselib.c.

89 {
90 int level = luaL_optint(L, 2, 1);
91 lua_settop(L, 1);
92 if (lua_isstring(L, 1) && level > 0) { /* add extra information? */
93 luaL_where(L, level);
94 lua_pushvalue(L, 1);
95 lua_concat(L, 2);
96 }
97 return lua_error(L);
98}
LUA_API void lua_concat(lua_State *L, int n)
LUALIB_API void luaL_where(lua_State *L, int level)

References lua_concat(), lua_error(), lua_isstring(), lua_pushvalue(), lua_settop(), luaL_optint, and luaL_where().

◆ luaB_getmetatable()

static int luaB_getmetatable ( lua_State * L)
static

Definition at line 101 of file lua-5.2.4/src/lbaselib.c.

101 {
102 luaL_checkany(L, 1);
103 if (!lua_getmetatable(L, 1)) {
104 lua_pushnil(L);
105 return 1; /* no metatable */
106 }
107 luaL_getmetafield(L, 1, "__metatable");
108 return 1; /* returns either __metatable field (if present) or metatable */
109}
LUA_API int lua_getmetatable(lua_State *L, int objindex)
LUALIB_API void luaL_checkany(lua_State *L, int narg)
LUALIB_API int luaL_getmetafield(lua_State *L, int obj, const char *event)

References lua_getmetatable(), lua_pushnil(), luaL_checkany(), and luaL_getmetafield().

◆ luaB_ipairs()

static int luaB_ipairs ( lua_State * L)
static

Definition at line 240 of file lua-5.2.4/src/lbaselib.c.

240 {
241 return pairsmeta(L, "__ipairs", 1, ipairsaux);
242}
static int pairsmeta(lua_State *L, const char *method, int iszero, lua_CFunction iter)
static int ipairsaux(lua_State *L)

References ipairsaux(), and pairsmeta().

◆ luaB_load()

static int luaB_load ( lua_State * L)
static

Definition at line 309 of file lua-5.2.4/src/lbaselib.c.

309 {
310 int status;
311 size_t l;
312 const char *s = lua_tolstring(L, 1, &l);
313 const char *mode = luaL_optstring(L, 3, "bt");
314 int env = (!lua_isnone(L, 4) ? 4 : 0); /* 'env' index or 0 if no 'env' */
315 if (s != NULL) { /* loading a string? */
316 const char *chunkname = luaL_optstring(L, 2, s);
317 status = luaL_loadbufferx(L, s, l, chunkname, mode);
318 }
319 else { /* loading from a reader function */
320 const char *chunkname = luaL_optstring(L, 2, "=(load)");
322 lua_settop(L, RESERVEDSLOT); /* create reserved slot */
323 status = lua_load(L, generic_reader, NULL, chunkname, mode);
324 }
325 return load_aux(L, status, env);
326}
LUA_API int lua_load(lua_State *L, lua_Reader reader, void *data, const char *chunkname)
#define lua_isnone(L, n)
#define LUA_TFUNCTION
LUALIB_API int luaL_loadbufferx(lua_State *L, const char *buff, size_t size, const char *name, const char *mode)
static int load_aux(lua_State *L, int status, int envidx)
static const char * generic_reader(lua_State *L, void *ud, size_t *size)
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

References generic_reader(), load_aux(), lua_isnone, lua_load(), lua_settop(), LUA_TFUNCTION, lua_tolstring(), luaL_checktype(), luaL_loadbufferx(), luaL_optstring, NULL, RESERVEDSLOT, and s.

◆ luaB_loadfile()

static int luaB_loadfile ( lua_State * L)
static

Definition at line 262 of file lua-5.2.4/src/lbaselib.c.

262 {
263 const char *fname = luaL_optstring(L, 1, NULL);
264 const char *mode = luaL_optstring(L, 2, NULL);
265 int env = (!lua_isnone(L, 3) ? 3 : 0); /* 'env' index or 0 if no 'env' */
266 int status = luaL_loadfilex(L, fname, mode);
267 return load_aux(L, status, env);
268}
LUALIB_API int luaL_loadfilex(lua_State *L, const char *filename, const char *mode)

References load_aux(), lua_isnone, luaL_loadfilex(), luaL_optstring, and NULL.

◆ luaB_next()

static int luaB_next ( lua_State * L)
static

Definition at line 213 of file lua-5.2.4/src/lbaselib.c.

213 {
215 lua_settop(L, 2); /* create a 2nd argument if there isn't one */
216 if (lua_next(L, 1))
217 return 2;
218 else {
219 lua_pushnil(L);
220 return 1;
221 }
222}
LUA_API int lua_next(lua_State *L, int idx)

References lua_next(), lua_pushnil(), lua_settop(), LUA_TTABLE, and luaL_checktype().

Referenced by luaB_pairs().

◆ luaB_pairs()

static int luaB_pairs ( lua_State * L)
static

Definition at line 225 of file lua-5.2.4/src/lbaselib.c.

225 {
226 return pairsmeta(L, "__pairs", 0, luaB_next);
227}
static int luaB_next(lua_State *L)

References luaB_next(), and pairsmeta().

◆ luaB_pcall()

static int luaB_pcall ( lua_State * L)
static

Definition at line 388 of file lua-5.2.4/src/lbaselib.c.

388 {
389 int status;
390 luaL_checkany(L, 1);
391 lua_pushnil(L);
392 lua_insert(L, 1); /* create space for status result */
393 status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, pcallcont);
394 return finishpcall(L, (status == LUA_OK));
395}
LUA_API int lua_pcallk(lua_State *L, int nargs, int nresults, int errfunc, int ctx, lua_CFunction k)
static int finishpcall(lua_State *L, int status)
static int pcallcont(lua_State *L)

References finishpcall(), lua_gettop(), lua_insert, LUA_MULTRET, LUA_OK, lua_pcallk(), lua_pushnil(), luaL_checkany(), and pcallcont().

◆ luaB_print()

static int luaB_print ( lua_State * L)
static

Definition at line 23 of file lua-5.2.4/src/lbaselib.c.

23 {
24 int n = lua_gettop(L); /* number of arguments */
25 int i;
26 lua_getglobal(L, "tostring");
27 for (i=1; i<=n; i++) {
28 const char *s;
29 size_t l;
30 lua_pushvalue(L, -1); /* function to be called */
31 lua_pushvalue(L, i); /* value to print */
32 lua_call(L, 1, 1);
33 s = lua_tolstring(L, -1, &l); /* get result */
34 if (s == NULL)
35 return luaL_error(L,
36 LUA_QL("tostring") " must return a string to " LUA_QL("print"));
37 if (i>1) luai_writestring("\t", 1);
38 luai_writestring(s, l);
39 lua_pop(L, 1); /* pop result */
40 }
41 luai_writeline();
42 return 0;
43}
#define lua_getglobal(L, s)
#define LUA_QL(x)

References lua_call, lua_getglobal, lua_gettop(), lua_pop, lua_pushvalue(), LUA_QL, lua_tolstring(), luaL_error(), NULL, and s.

◆ luaB_rawequal()

static int luaB_rawequal ( lua_State * L)
static

Definition at line 125 of file lua-5.2.4/src/lbaselib.c.

125 {
126 luaL_checkany(L, 1);
127 luaL_checkany(L, 2);
128 lua_pushboolean(L, lua_rawequal(L, 1, 2));
129 return 1;
130}
LUA_API int lua_rawequal(lua_State *L, int index1, int index2)

References lua_pushboolean(), lua_rawequal(), and luaL_checkany().

◆ luaB_rawget()

static int luaB_rawget ( lua_State * L)
static

Definition at line 142 of file lua-5.2.4/src/lbaselib.c.

142 {
144 luaL_checkany(L, 2);
145 lua_settop(L, 2);
146 lua_rawget(L, 1);
147 return 1;
148}
LUA_API void lua_rawget(lua_State *L, int idx)

References lua_rawget(), lua_settop(), LUA_TTABLE, luaL_checkany(), and luaL_checktype().

◆ luaB_rawlen()

static int luaB_rawlen ( lua_State * L)
static

Definition at line 133 of file lua-5.2.4/src/lbaselib.c.

133 {
134 int t = lua_type(L, 1);
135 luaL_argcheck(L, t == LUA_TTABLE || t == LUA_TSTRING, 1,
136 "table or string expected");
137 lua_pushinteger(L, lua_rawlen(L, 1));
138 return 1;
139}
#define lua_rawlen(L, index)
Definition LuaXML_lib.c:42
LUA_API int lua_type(lua_State *L, int idx)
#define luaL_argcheck(L, cond, numarg, extramsg)
#define LUA_TSTRING

References lua_pushinteger(), lua_rawlen, LUA_TSTRING, LUA_TTABLE, lua_type(), and luaL_argcheck.

◆ luaB_rawset()

static int luaB_rawset ( lua_State * L)
static

Definition at line 150 of file lua-5.2.4/src/lbaselib.c.

150 {
152 luaL_checkany(L, 2);
153 luaL_checkany(L, 3);
154 lua_settop(L, 3);
155 lua_rawset(L, 1);
156 return 1;
157}
LUA_API void lua_rawset(lua_State *L, int idx)

References lua_rawset(), lua_settop(), LUA_TTABLE, luaL_checkany(), and luaL_checktype().

◆ luaB_select()

static int luaB_select ( lua_State * L)
static

Definition at line 353 of file lua-5.2.4/src/lbaselib.c.

353 {
354 int n = lua_gettop(L);
355 if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {
356 lua_pushinteger(L, n-1);
357 return 1;
358 }
359 else {
360 int i = luaL_checkint(L, 1);
361 if (i < 0) i = n + i;
362 else if (i > n) i = n;
363 luaL_argcheck(L, 1 <= i, 1, "index out of range");
364 return n - i;
365 }
366}
#define lua_tostring(L, i)

References lua_gettop(), lua_pushinteger(), lua_tostring, LUA_TSTRING, lua_type(), luaL_argcheck, and luaL_checkint.

◆ luaB_setmetatable()

static int luaB_setmetatable ( lua_State * L)
static

Definition at line 112 of file lua-5.2.4/src/lbaselib.c.

112 {
113 int t = lua_type(L, 2);
115 luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
116 "nil or table expected");
117 if (luaL_getmetafield(L, 1, "__metatable"))
118 return luaL_error(L, "cannot change a protected metatable");
119 lua_settop(L, 2);
120 lua_setmetatable(L, 1);
121 return 1;
122}
LUA_API int lua_setmetatable(lua_State *L, int objindex)
#define LUA_TNIL

References lua_setmetatable(), lua_settop(), LUA_TNIL, LUA_TTABLE, lua_type(), luaL_argcheck, luaL_checktype(), luaL_error(), and luaL_getmetafield().

◆ luaB_tonumber()

static int luaB_tonumber ( lua_State * L)
static

Definition at line 48 of file lua-5.2.4/src/lbaselib.c.

48 {
49 if (lua_isnoneornil(L, 2)) { /* standard conversion */
50 int isnum;
51 lua_Number n = lua_tonumberx(L, 1, &isnum);
52 if (isnum) {
53 lua_pushnumber(L, n);
54 return 1;
55 } /* else not a number; must be something */
56 luaL_checkany(L, 1);
57 }
58 else {
59 size_t l;
60 const char *s = luaL_checklstring(L, 1, &l);
61 const char *e = s + l; /* end point for 's' */
62 int base = luaL_checkint(L, 2);
63 int neg = 0;
64 luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
65 s += strspn(s, SPACECHARS); /* skip initial spaces */
66 if (*s == '-') { s++; neg = 1; } /* handle signal */
67 else if (*s == '+') s++;
68 if (isalnum((unsigned char)*s)) {
69 lua_Number n = 0;
70 do {
71 int digit = (isdigit((unsigned char)*s)) ? *s - '0'
72 : toupper((unsigned char)*s) - 'A' + 10;
73 if (digit >= base) break; /* invalid numeral; force a fail */
74 n = n * (lua_Number)base + (lua_Number)digit;
75 s++;
76 } while (isalnum((unsigned char)*s));
77 s += strspn(s, SPACECHARS); /* skip trailing spaces */
78 if (s == e) { /* no invalid trailing characters? */
79 lua_pushnumber(L, (neg) ? -n : n);
80 return 1;
81 } /* else not a number */
82 } /* else not a number */
83 }
84 lua_pushnil(L); /* not a number */
85 return 1;
86}
LUALIB_API const char * luaL_checklstring(lua_State *L, int narg, size_t *len)
#define lua_isnoneornil(L, n)
LUA_API lua_Number lua_tonumberx(lua_State *L, int idx, int *isnum)
#define SPACECHARS
static int digit(int c)

References digit(), lua_isnoneornil, lua_pushnil(), lua_pushnumber(), lua_tonumberx(), luaL_argcheck, luaL_checkany(), luaL_checkint, luaL_checklstring(), s, and SPACECHARS.

◆ luaB_tostring()

static int luaB_tostring ( lua_State * L)
static

Definition at line 410 of file lua-5.2.4/src/lbaselib.c.

410 {
411 luaL_checkany(L, 1);
412 luaL_tolstring(L, 1, NULL);
413 return 1;
414}
LUALIB_API const char * luaL_tolstring(lua_State *L, int idx, size_t *len)

References luaL_checkany(), luaL_tolstring(), and NULL.

◆ luaB_type()

static int luaB_type ( lua_State * L)
static

Definition at line 189 of file lua-5.2.4/src/lbaselib.c.

189 {
190 luaL_checkany(L, 1);
192 return 1;
193}
#define luaL_typename(L, i)

References lua_pushstring(), luaL_checkany(), and luaL_typename.

◆ luaB_xpcall()

static int luaB_xpcall ( lua_State * L)
static

Definition at line 398 of file lua-5.2.4/src/lbaselib.c.

398 {
399 int status;
400 int n = lua_gettop(L);
401 luaL_argcheck(L, n >= 2, 2, "value expected");
402 lua_pushvalue(L, 1); /* exchange function... */
403 lua_copy(L, 2, 1); /* ...and error handler */
404 lua_replace(L, 2);
405 status = lua_pcallk(L, n - 2, LUA_MULTRET, 1, 0, pcallcont);
406 return finishpcall(L, (status == LUA_OK));
407}
LUA_API void lua_copy(lua_State *L, int fromidx, int toidx)

References finishpcall(), lua_copy(), lua_gettop(), LUA_MULTRET, LUA_OK, lua_pcallk(), lua_pushvalue(), lua_replace, luaL_argcheck, and pcallcont().

◆ luaopen_base()

LUAMOD_API int luaopen_base ( lua_State * L)

Definition at line 447 of file lua-5.2.4/src/lbaselib.c.

447 {
448 /* set global _G */
451 lua_setfield(L, -2, "_G");
452 /* open lib into global table */
455 lua_setfield(L, -2, "_VERSION"); /* set global _VERSION */
456 return 1;
457}
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
#define LUA_VERSION
#define lua_pushliteral(L, s)
LUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
static const luaL_Reg base_funcs[]
#define lua_pushglobaltable(L)

References base_funcs, lua_pushglobaltable, lua_pushliteral, lua_setfield(), LUA_VERSION, and luaL_setfuncs().

◆ pairsmeta()

static int pairsmeta ( lua_State * L,
const char * method,
int iszero,
lua_CFunction iter )
static

Definition at line 196 of file lua-5.2.4/src/lbaselib.c.

197 {
198 if (!luaL_getmetafield(L, 1, method)) { /* no metamethod? */
199 luaL_checktype(L, 1, LUA_TTABLE); /* argument must be a table */
200 lua_pushcfunction(L, iter); /* will return generator, */
201 lua_pushvalue(L, 1); /* state, */
202 if (iszero) lua_pushinteger(L, 0); /* and initial value */
203 else lua_pushnil(L);
204 }
205 else {
206 lua_pushvalue(L, 1); /* argument 'self' to metamethod */
207 lua_call(L, 1, 3); /* get 3 values from metamethod */
208 }
209 return 3;
210}
#define lua_pushcfunction(L, f)

References lua_call, lua_pushcfunction, lua_pushinteger(), lua_pushnil(), lua_pushvalue(), LUA_TTABLE, luaL_checktype(), and luaL_getmetafield().

Referenced by luaB_ipairs(), and luaB_pairs().

◆ pcallcont()

static int pcallcont ( lua_State * L)
static

Definition at line 382 of file lua-5.2.4/src/lbaselib.c.

382 {
383 int status = lua_getctx(L, NULL);
384 return finishpcall(L, (status == LUA_YIELD));
385}
#define LUA_YIELD
LUA_API int lua_getctx(lua_State *L, int *ctx)

References finishpcall(), lua_getctx(), LUA_YIELD, and NULL.

Referenced by luaB_pcall(), and luaB_xpcall().

Variable Documentation

◆ base_funcs

const luaL_Reg base_funcs[]
static
Initial value:
= {
{"assert", luaB_assert},
{"collectgarbage", luaB_collectgarbage},
{"dofile", luaB_dofile},
{"error", luaB_error},
{"getmetatable", luaB_getmetatable},
{"ipairs", luaB_ipairs},
{"loadfile", luaB_loadfile},
{"load", luaB_load},
{"next", luaB_next},
{"pairs", luaB_pairs},
{"pcall", luaB_pcall},
{"print", luaB_print},
{"rawequal", luaB_rawequal},
{"rawlen", luaB_rawlen},
{"rawget", luaB_rawget},
{"rawset", luaB_rawset},
{"select", luaB_select},
{"setmetatable", luaB_setmetatable},
{"tonumber", luaB_tonumber},
{"tostring", luaB_tostring},
{"type", luaB_type},
{"xpcall", luaB_xpcall},
}
static int luaB_collectgarbage(lua_State *L)
static int luaB_tostring(lua_State *L)
static int luaB_pcall(lua_State *L)
static int luaB_rawget(lua_State *L)
static int luaB_error(lua_State *L)
static int luaB_pairs(lua_State *L)
static int luaB_load(lua_State *L)
static int luaB_rawequal(lua_State *L)
static int luaB_ipairs(lua_State *L)
static int luaB_xpcall(lua_State *L)
static int luaB_tonumber(lua_State *L)
static int luaB_rawlen(lua_State *L)
static int luaB_type(lua_State *L)
static int luaB_rawset(lua_State *L)
static int luaB_print(lua_State *L)
static int luaB_dofile(lua_State *L)
static int luaB_assert(lua_State *L)
static int luaB_select(lua_State *L)
static int luaB_getmetatable(lua_State *L)
static int luaB_loadfile(lua_State *L)
static int luaB_setmetatable(lua_State *L)

Definition at line 417 of file lua-5.2.4/src/lbaselib.c.

417 {
418 {"assert", luaB_assert},
419 {"collectgarbage", luaB_collectgarbage},
420 {"dofile", luaB_dofile},
421 {"error", luaB_error},
422 {"getmetatable", luaB_getmetatable},
423 {"ipairs", luaB_ipairs},
424 {"loadfile", luaB_loadfile},
425 {"load", luaB_load},
426#if defined(LUA_COMPAT_LOADSTRING)
427 {"loadstring", luaB_load},
428#endif
429 {"next", luaB_next},
430 {"pairs", luaB_pairs},
431 {"pcall", luaB_pcall},
432 {"print", luaB_print},
433 {"rawequal", luaB_rawequal},
434 {"rawlen", luaB_rawlen},
435 {"rawget", luaB_rawget},
436 {"rawset", luaB_rawset},
437 {"select", luaB_select},
438 {"setmetatable", luaB_setmetatable},
439 {"tonumber", luaB_tonumber},
440 {"tostring", luaB_tostring},
441 {"type", luaB_type},
442 {"xpcall", luaB_xpcall},
443 {NULL, NULL}
444};

Referenced by luaopen_base().