Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lbaselib.c File Reference
#include "lprefix.h"
#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 const char * b_str2int (const char *s, int base, lua_Integer *pn)
 
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, int d1, lua_KContext d2)
 
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, lua_KContext extra)
 
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 7 of file lua-5.3.6/src/lbaselib.c.

◆ LUA_LIB

#define LUA_LIB

Definition at line 8 of file lua-5.3.6/src/lbaselib.c.

◆ RESERVEDSLOT

#define RESERVEDSLOT   5

Definition at line 308 of file lua-5.3.6/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.3.6/src/lbaselib.c.

Referenced by b_str2int().

Function Documentation

◆ b_str2int()

static const char * b_str2int ( const char * s,
int base,
lua_Integer * pn )
static

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

48 {
49 lua_Unsigned n = 0;
50 int neg = 0;
51 s += strspn(s, SPACECHARS); /* skip initial spaces */
52 if (*s == '-') { s++; neg = 1; } /* handle signal */
53 else if (*s == '+') s++;
54 if (!isalnum((unsigned char)*s)) /* no digit? */
55 return NULL;
56 do {
57 int digit = (isdigit((unsigned char)*s)) ? *s - '0'
58 : (toupper((unsigned char)*s) - 'A') + 10;
59 if (digit >= base) return NULL; /* invalid numeral */
60 n = n * base + digit;
61 s++;
62 } while (isalnum((unsigned char)*s));
63 s += strspn(s, SPACECHARS); /* skip trailing spaces */
64 *pn = (lua_Integer)((neg) ? (0u - n) : n);
65 return s;
66}
#define NULL
Definition gmacros.h:924
LUA_INTEGER lua_Integer
LUA_UNSIGNED lua_Unsigned
#define SPACECHARS
static int digit(int c)
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

References digit(), NULL, s, and SPACECHARS.

Referenced by luaB_tonumber().

◆ dofilecont()

static int dofilecont ( lua_State * L,
int d1,
lua_KContext d2 )
static

Definition at line 356 of file lua-5.3.6/src/lbaselib.c.

356 {
357 (void)d1; (void)d2; /* only to match 'lua_Kfunction' prototype */
358 return lua_gettop(L) - 1;
359}
LUA_API int lua_gettop(lua_State *L)

References lua_gettop().

Referenced by luaB_dofile().

◆ finishpcall()

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

Definition at line 408 of file lua-5.3.6/src/lbaselib.c.

408 {
409 if (status != LUA_OK && status != LUA_YIELD) { /* error? */
410 lua_pushboolean(L, 0); /* first result (false) */
411 lua_pushvalue(L, -2); /* error message */
412 return 2; /* return false, msg */
413 }
414 else
415 return lua_gettop(L) - (int)extra; /* return all results */
416}
LUA_API void lua_pushboolean(lua_State *L, int b)
LUA_API void lua_pushvalue(lua_State *L, int idx)
#define LUA_YIELD
#define LUA_OK

References lua_gettop(), LUA_OK, lua_pushboolean(), lua_pushvalue(), and LUA_YIELD.

Referenced by luaB_pcall(), and luaB_xpcall().

◆ generic_reader()

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

Definition at line 317 of file lua-5.3.6/src/lbaselib.c.

317 {
318 (void)(ud); /* not used */
319 luaL_checkstack(L, 2, "too many nested functions");
320 lua_pushvalue(L, 1); /* get function */
321 lua_call(L, 0, 1); /* call it */
322 if (lua_isnil(L, -1)) {
323 lua_pop(L, 1); /* pop result */
324 *size = 0;
325 return NULL;
326 }
327 else if (!lua_isstring(L, -1))
328 luaL_error(L, "reader function must return a string");
329 lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */
330 return lua_tolstring(L, RESERVEDSLOT, size);
331}
LUA_API const char * lua_tolstring(lua_State *L, int idx, size_t *len)
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 lua_call(L, n, r)
#define RESERVEDSLOT
#define lua_replace(L, idx)

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 246 of file lua-5.3.6/src/lbaselib.c.

246 {
247 lua_Integer i = luaL_checkinteger(L, 2) + 1;
248 lua_pushinteger(L, i);
249 return (lua_geti(L, 1, i) == LUA_TNIL) ? 1 : 2;
250}
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int narg)
#define LUA_TNIL
LUA_API int lua_geti(lua_State *L, int idx, lua_Integer n)

References lua_geti(), lua_pushinteger(), LUA_TNIL, and luaL_checkinteger().

Referenced by luaB_ipairs().

◆ load_aux()

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

Definition at line 270 of file lua-5.3.6/src/lbaselib.c.

270 {
271 if (status == LUA_OK) {
272 if (envidx != 0) { /* 'env' parameter? */
273 lua_pushvalue(L, envidx); /* environment for loaded function */
274 if (!lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */
275 lua_pop(L, 1); /* remove 'env' if not used by previous call */
276 }
277 return 1;
278 }
279 else { /* error (message is on top of the stack) */
280 lua_pushnil(L);
281 lua_insert(L, -2); /* put before error message */
282 return 2; /* return nil plus error message */
283 }
284}
LUA_API void lua_pushnil(lua_State *L)
LUA_API const char * lua_setupvalue(lua_State *L, int funcindex, int n)
#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 372 of file lua-5.3.6/src/lbaselib.c.

372 {
373 if (lua_toboolean(L, 1)) /* condition is true? */
374 return lua_gettop(L); /* return all arguments */
375 else { /* error */
376 luaL_checkany(L, 1); /* there must be a condition */
377 lua_remove(L, 1); /* remove it */
378 lua_pushliteral(L, "assertion failed!"); /* default message */
379 lua_settop(L, 1); /* leave only message (default if no other one) */
380 return luaB_error(L); /* call 'error' */
381 }
382}
LUA_API int lua_toboolean(lua_State *L, int idx)
LUA_API void lua_settop(lua_State *L, int idx)
LUALIB_API void luaL_checkany(lua_State *L, int narg)
#define lua_pushliteral(L, s)
static int luaB_error(lua_State *L)
#define lua_remove(L, idx)

References lua_gettop(), lua_pushliteral, lua_remove, lua_settop(), lua_toboolean(), luaB_error(), and luaL_checkany().

◆ luaB_collectgarbage()

static int luaB_collectgarbage ( lua_State * L)
static

Definition at line 173 of file lua-5.3.6/src/lbaselib.c.

173 {
174 static const char *const opts[] = {"stop", "restart", "collect",
175 "count", "step", "setpause", "setstepmul",
176 "isrunning", NULL};
177 static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
180 int o = optsnum[luaL_checkoption(L, 1, "collect", opts)];
181 int ex = (int)luaL_optinteger(L, 2, 0);
182 int res = lua_gc(L, o, ex);
183 switch (o) {
184 case LUA_GCCOUNT: {
185 int b = lua_gc(L, LUA_GCCOUNTB, 0);
186 lua_pushnumber(L, (lua_Number)res + ((lua_Number)b/1024));
187 return 1;
188 }
189 case LUA_GCSTEP: case LUA_GCISRUNNING: {
190 lua_pushboolean(L, res);
191 return 1;
192 }
193 default: {
194 lua_pushinteger(L, res);
195 return 1;
196 }
197 }
198}
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 lua_Integer luaL_optinteger(lua_State *L, int narg, lua_Integer def)
LUALIB_API int luaL_checkoption(lua_State *L, int narg, const char *def, const char *const lst[])
#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_GCISRUNNING

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

◆ luaB_dofile()

static int luaB_dofile ( lua_State * L)
static

Definition at line 362 of file lua-5.3.6/src/lbaselib.c.

362 {
363 const char *fname = luaL_optstring(L, 1, NULL);
364 lua_settop(L, 1);
365 if (luaL_loadfile(L, fname) != LUA_OK)
366 return lua_error(L);
368 return dofilecont(L, 0, 0);
369}
LUA_API int lua_error(lua_State *L)
#define luaL_optstring(L, n, d)
#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, int d1, lua_KContext d2)

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 102 of file lua-5.3.6/src/lbaselib.c.

102 {
103 int level = (int)luaL_optinteger(L, 2, 1);
104 lua_settop(L, 1);
105 if (lua_type(L, 1) == LUA_TSTRING && level > 0) {
106 luaL_where(L, level); /* add extra information */
107 lua_pushvalue(L, 1);
108 lua_concat(L, 2);
109 }
110 return lua_error(L);
111}
LUA_API void lua_concat(lua_State *L, int n)
LUA_API int lua_type(lua_State *L, int idx)
LUALIB_API void luaL_where(lua_State *L, int level)
#define LUA_TSTRING

References lua_concat(), lua_error(), lua_pushvalue(), lua_settop(), LUA_TSTRING, lua_type(), luaL_optinteger(), and luaL_where().

Referenced by luaB_assert().

◆ luaB_getmetatable()

static int luaB_getmetatable ( lua_State * L)
static

Definition at line 114 of file lua-5.3.6/src/lbaselib.c.

114 {
115 luaL_checkany(L, 1);
116 if (!lua_getmetatable(L, 1)) {
117 lua_pushnil(L);
118 return 1; /* no metatable */
119 }
120 luaL_getmetafield(L, 1, "__metatable");
121 return 1; /* returns either __metatable field (if present) or metatable */
122}
LUA_API int lua_getmetatable(lua_State *L, int objindex)
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 257 of file lua-5.3.6/src/lbaselib.c.

257 {
258#if defined(LUA_COMPAT_IPAIRS)
259 return pairsmeta(L, "__ipairs", 1, ipairsaux);
260#else
261 luaL_checkany(L, 1);
262 lua_pushcfunction(L, ipairsaux); /* iteration function */
263 lua_pushvalue(L, 1); /* state */
264 lua_pushinteger(L, 0); /* initial value */
265 return 3;
266#endif
267}
#define lua_pushcfunction(L, f)
static int pairsmeta(lua_State *L, const char *method, int iszero, lua_CFunction iter)
static int ipairsaux(lua_State *L)

References ipairsaux(), lua_pushcfunction, lua_pushinteger(), lua_pushvalue(), luaL_checkany(), and pairsmeta().

◆ luaB_load()

static int luaB_load ( lua_State * L)
static

Definition at line 334 of file lua-5.3.6/src/lbaselib.c.

334 {
335 int status;
336 size_t l;
337 const char *s = lua_tolstring(L, 1, &l);
338 const char *mode = luaL_optstring(L, 3, "bt");
339 int env = (!lua_isnone(L, 4) ? 4 : 0); /* 'env' index or 0 if no 'env' */
340 if (s != NULL) { /* loading a string? */
341 const char *chunkname = luaL_optstring(L, 2, s);
342 status = luaL_loadbufferx(L, s, l, chunkname, mode);
343 }
344 else { /* loading from a reader function */
345 const char *chunkname = luaL_optstring(L, 2, "=(load)");
347 lua_settop(L, RESERVEDSLOT); /* create reserved slot */
348 status = lua_load(L, generic_reader, NULL, chunkname, mode);
349 }
350 return load_aux(L, status, env);
351}
LUA_API int lua_load(lua_State *L, lua_Reader reader, void *data, const char *chunkname)
LUALIB_API void luaL_checktype(lua_State *L, int narg, int t)
#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)

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 287 of file lua-5.3.6/src/lbaselib.c.

287 {
288 const char *fname = luaL_optstring(L, 1, NULL);
289 const char *mode = luaL_optstring(L, 2, NULL);
290 int env = (!lua_isnone(L, 3) ? 3 : 0); /* 'env' index or 0 if no 'env' */
291 int status = luaL_loadfilex(L, fname, mode);
292 return load_aux(L, status, env);
293}
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 226 of file lua-5.3.6/src/lbaselib.c.

226 {
228 lua_settop(L, 2); /* create a 2nd argument if there isn't one */
229 if (lua_next(L, 1))
230 return 2;
231 else {
232 lua_pushnil(L);
233 return 1;
234 }
235}
LUA_API int lua_next(lua_State *L, int idx)
#define LUA_TTABLE

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 238 of file lua-5.3.6/src/lbaselib.c.

238 {
239 return pairsmeta(L, "__pairs", 0, luaB_next);
240}
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 419 of file lua-5.3.6/src/lbaselib.c.

419 {
420 int status;
421 luaL_checkany(L, 1);
422 lua_pushboolean(L, 1); /* first result if no errors */
423 lua_insert(L, 1); /* put it in place */
424 status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, finishpcall);
425 return finishpcall(L, status, 0);
426}
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, lua_KContext extra)

References finishpcall(), lua_gettop(), lua_insert, LUA_MULTRET, lua_pcallk(), lua_pushboolean(), and luaL_checkany().

◆ luaB_print()

static int luaB_print ( lua_State * L)
static

Definition at line 24 of file lua-5.3.6/src/lbaselib.c.

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

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

◆ luaB_rawequal()

static int luaB_rawequal ( lua_State * L)
static

Definition at line 138 of file lua-5.3.6/src/lbaselib.c.

138 {
139 luaL_checkany(L, 1);
140 luaL_checkany(L, 2);
141 lua_pushboolean(L, lua_rawequal(L, 1, 2));
142 return 1;
143}
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 155 of file lua-5.3.6/src/lbaselib.c.

155 {
157 luaL_checkany(L, 2);
158 lua_settop(L, 2);
159 lua_rawget(L, 1);
160 return 1;
161}
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 146 of file lua-5.3.6/src/lbaselib.c.

146 {
147 int t = lua_type(L, 1);
148 luaL_argcheck(L, t == LUA_TTABLE || t == LUA_TSTRING, 1,
149 "table or string expected");
150 lua_pushinteger(L, lua_rawlen(L, 1));
151 return 1;
152}
#define lua_rawlen(L, index)
Definition LuaXML_lib.c:42
#define luaL_argcheck(L, cond, numarg, extramsg)

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 163 of file lua-5.3.6/src/lbaselib.c.

163 {
165 luaL_checkany(L, 2);
166 luaL_checkany(L, 3);
167 lua_settop(L, 3);
168 lua_rawset(L, 1);
169 return 1;
170}
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 385 of file lua-5.3.6/src/lbaselib.c.

385 {
386 int n = lua_gettop(L);
387 if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {
388 lua_pushinteger(L, n-1);
389 return 1;
390 }
391 else {
393 if (i < 0) i = n + i;
394 else if (i > n) i = n;
395 luaL_argcheck(L, 1 <= i, 1, "index out of range");
396 return n - (int)i;
397 }
398}
#define lua_tostring(L, i)

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

◆ luaB_setmetatable()

static int luaB_setmetatable ( lua_State * L)
static

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

125 {
126 int t = lua_type(L, 2);
128 luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
129 "nil or table expected");
130 if (luaL_getmetafield(L, 1, "__metatable") != LUA_TNIL)
131 return luaL_error(L, "cannot change a protected metatable");
132 lua_settop(L, 2);
133 lua_setmetatable(L, 1);
134 return 1;
135}
LUA_API int lua_setmetatable(lua_State *L, int objindex)

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 69 of file lua-5.3.6/src/lbaselib.c.

69 {
70 if (lua_isnoneornil(L, 2)) { /* standard conversion? */
71 luaL_checkany(L, 1);
72 if (lua_type(L, 1) == LUA_TNUMBER) { /* already a number? */
73 lua_settop(L, 1); /* yes; return it */
74 return 1;
75 }
76 else {
77 size_t l;
78 const char *s = lua_tolstring(L, 1, &l);
79 if (s != NULL && lua_stringtonumber(L, s) == l + 1)
80 return 1; /* successful conversion to number */
81 /* else not a number */
82 }
83 }
84 else {
85 size_t l;
86 const char *s;
87 lua_Integer n = 0; /* to avoid warnings */
88 lua_Integer base = luaL_checkinteger(L, 2);
89 luaL_checktype(L, 1, LUA_TSTRING); /* no numbers as strings */
90 s = lua_tolstring(L, 1, &l);
91 luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
92 if (b_str2int(s, (int)base, &n) == s + l) {
93 lua_pushinteger(L, n);
94 return 1;
95 } /* else not a number */
96 } /* else not a number */
97 lua_pushnil(L); /* not a number */
98 return 1;
99}
#define LUA_TNUMBER
#define lua_isnoneornil(L, n)
LUA_API size_t lua_stringtonumber(lua_State *L, const char *s)
static const char * b_str2int(const char *s, int base, lua_Integer *pn)

References b_str2int(), lua_isnoneornil, lua_pushinteger(), lua_pushnil(), lua_settop(), lua_stringtonumber(), LUA_TNUMBER, lua_tolstring(), LUA_TSTRING, lua_type(), luaL_argcheck, luaL_checkany(), luaL_checkinteger(), luaL_checktype(), NULL, and s.

◆ luaB_tostring()

static int luaB_tostring ( lua_State * L)
static

Definition at line 446 of file lua-5.3.6/src/lbaselib.c.

446 {
447 luaL_checkany(L, 1);
448 luaL_tolstring(L, 1, NULL);
449 return 1;
450}
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 201 of file lua-5.3.6/src/lbaselib.c.

201 {
202 int t = lua_type(L, 1);
203 luaL_argcheck(L, t != LUA_TNONE, 1, "value expected");
205 return 1;
206}
LUA_API void lua_pushstring(lua_State *L, const char *s)
LUA_API const char * lua_typename(lua_State *L, int t)
#define LUA_TNONE

References lua_pushstring(), LUA_TNONE, lua_type(), lua_typename(), and luaL_argcheck.

◆ luaB_xpcall()

static int luaB_xpcall ( lua_State * L)
static

Definition at line 434 of file lua-5.3.6/src/lbaselib.c.

434 {
435 int status;
436 int n = lua_gettop(L);
437 luaL_checktype(L, 2, LUA_TFUNCTION); /* check error function */
438 lua_pushboolean(L, 1); /* first result */
439 lua_pushvalue(L, 1); /* function */
440 lua_rotate(L, 3, 2); /* move them below function's arguments */
441 status = lua_pcallk(L, n - 2, LUA_MULTRET, 2, 2, finishpcall);
442 return finishpcall(L, status, 2);
443}
LUA_API void lua_rotate(lua_State *L, int idx, int n)

References finishpcall(), lua_gettop(), LUA_MULTRET, lua_pcallk(), lua_pushboolean(), lua_pushvalue(), lua_rotate(), LUA_TFUNCTION, and luaL_checktype().

◆ luaopen_base()

LUAMOD_API int luaopen_base ( lua_State * L)

Definition at line 486 of file lua-5.3.6/src/lbaselib.c.

486 {
487 /* open lib into global table */
490 /* set global _G */
491 lua_pushvalue(L, -1);
492 lua_setfield(L, -2, "_G");
493 /* set global _VERSION */
495 lua_setfield(L, -2, "_VERSION");
496 return 1;
497}
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
#define LUA_VERSION
LUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
#define lua_pushglobaltable(L)
static const luaL_Reg base_funcs[]

References base_funcs, lua_pushglobaltable, lua_pushliteral, lua_pushvalue(), 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 209 of file lua-5.3.6/src/lbaselib.c.

210 {
211 luaL_checkany(L, 1);
212 if (luaL_getmetafield(L, 1, method) == LUA_TNIL) { /* no metamethod? */
213 lua_pushcfunction(L, iter); /* will return generator, */
214 lua_pushvalue(L, 1); /* state, */
215 if (iszero) lua_pushinteger(L, 0); /* and initial value */
216 else lua_pushnil(L);
217 }
218 else {
219 lua_pushvalue(L, 1); /* argument 'self' to metamethod */
220 lua_call(L, 1, 3); /* get 3 values from metamethod */
221 }
222 return 3;
223}

References lua_call, lua_pushcfunction, lua_pushinteger(), lua_pushnil(), lua_pushvalue(), LUA_TNIL, luaL_checkany(), and luaL_getmetafield().

Referenced by luaB_ipairs(), and luaB_pairs().

Variable Documentation

◆ base_funcs

const luaL_Reg base_funcs[]
static

Definition at line 453 of file lua-5.3.6/src/lbaselib.c.

453 {
454 {"assert", luaB_assert},
455 {"collectgarbage", luaB_collectgarbage},
456 {"dofile", luaB_dofile},
457 {"error", luaB_error},
458 {"getmetatable", luaB_getmetatable},
459 {"ipairs", luaB_ipairs},
460 {"loadfile", luaB_loadfile},
461 {"load", luaB_load},
462#if defined(LUA_COMPAT_LOADSTRING)
463 {"loadstring", luaB_load},
464#endif
465 {"next", luaB_next},
466 {"pairs", luaB_pairs},
467 {"pcall", luaB_pcall},
468 {"print", luaB_print},
469 {"rawequal", luaB_rawequal},
470 {"rawlen", luaB_rawlen},
471 {"rawget", luaB_rawget},
472 {"rawset", luaB_rawset},
473 {"select", luaB_select},
474 {"setmetatable", luaB_setmetatable},
475 {"tonumber", luaB_tonumber},
476 {"tostring", luaB_tostring},
477 {"type", luaB_type},
478 {"xpcall", luaB_xpcall},
479 /* placeholders */
480 {"_G", NULL},
481 {"_VERSION", NULL},
482 {NULL, NULL}
483};
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_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)

Referenced by luaopen_base().