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 int luaB_warn (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 pushmode (lua_State *L, int oldmode)
 
static int luaB_collectgarbage (lua_State *L)
 
static int luaB_type (lua_State *L)
 
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.4.3/src/lbaselib.c.

◆ LUA_LIB

#define LUA_LIB

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

◆ RESERVEDSLOT

#define RESERVEDSLOT   5

Definition at line 340 of file lua-5.4.3/src/lbaselib.c.

Referenced by generic_reader(), and luaB_load().

◆ SPACECHARS

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

Definition at line 58 of file lua-5.4.3/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 60 of file lua-5.4.3/src/lbaselib.c.

60 {
61 lua_Unsigned n = 0;
62 int neg = 0;
63 s += strspn(s, SPACECHARS); /* skip initial spaces */
64 if (*s == '-') { s++; neg = 1; } /* handle sign */
65 else if (*s == '+') s++;
66 if (!isalnum((unsigned char)*s)) /* no digit? */
67 return NULL;
68 do {
69 int digit = (isdigit((unsigned char)*s)) ? *s - '0'
70 : (toupper((unsigned char)*s) - 'A') + 10;
71 if (digit >= base) return NULL; /* invalid numeral */
72 n = n * base + digit;
73 s++;
74 } while (isalnum((unsigned char)*s));
75 s += strspn(s, SPACECHARS); /* skip trailing spaces */
76 *pn = (lua_Integer)((neg) ? (0u - n) : n);
77 return s;
78}
#define NULL
Definition gmacros.h:924
LUA_INTEGER lua_Integer
LUA_UNSIGNED lua_Unsigned
static int digit(int c)
#define SPACECHARS
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 388 of file lua-5.4.3/src/lbaselib.c.

388 {
389 (void)d1; (void)d2; /* only to match 'lua_Kfunction' prototype */
390 return lua_gettop(L) - 1;
391}
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 440 of file lua-5.4.3/src/lbaselib.c.

440 {
441 if (l_unlikely(status != LUA_OK && status != LUA_YIELD)) { /* error? */
442 lua_pushboolean(L, 0); /* first result (false) */
443 lua_pushvalue(L, -2); /* error message */
444 return 2; /* return false, msg */
445 }
446 else
447 return lua_gettop(L) - (int)extra; /* return all results */
448}
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 349 of file lua-5.4.3/src/lbaselib.c.

349 {
350 (void)(ud); /* not used */
351 luaL_checkstack(L, 2, "too many nested functions");
352 lua_pushvalue(L, 1); /* get function */
353 lua_call(L, 0, 1); /* call it */
354 if (lua_isnil(L, -1)) {
355 lua_pop(L, 1); /* pop result */
356 *size = 0;
357 return NULL;
358 }
359 else if (l_unlikely(!lua_isstring(L, -1)))
360 luaL_error(L, "reader function must return a string");
361 lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */
362 return lua_tolstring(L, RESERVEDSLOT, size);
363}
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 lua_replace(L, idx)
#define RESERVEDSLOT

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

282 {
283 lua_Integer i = luaL_checkinteger(L, 2) + 1;
284 lua_pushinteger(L, i);
285 return (lua_geti(L, 1, i) == LUA_TNIL) ? 1 : 2;
286}
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 302 of file lua-5.4.3/src/lbaselib.c.

302 {
303 if (l_likely(status == LUA_OK)) {
304 if (envidx != 0) { /* 'env' parameter? */
305 lua_pushvalue(L, envidx); /* environment for loaded function */
306 if (!lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */
307 lua_pop(L, 1); /* remove 'env' if not used by previous call */
308 }
309 return 1;
310 }
311 else { /* error (message is on top of the stack) */
312 luaL_pushfail(L);
313 lua_insert(L, -2); /* put before error message */
314 return 2; /* return fail plus error message */
315 }
316}
LUA_API const char * lua_setupvalue(lua_State *L, int funcindex, int n)
#define lua_insert(L, idx)
#define luaL_pushfail(L)

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

Referenced by luaB_load(), and luaB_loadfile().

◆ luaB_assert()

static int luaB_assert ( lua_State * L)
static

Definition at line 404 of file lua-5.4.3/src/lbaselib.c.

404 {
405 if (l_likely(lua_toboolean(L, 1))) /* condition is true? */
406 return lua_gettop(L); /* return all arguments */
407 else { /* error */
408 luaL_checkany(L, 1); /* there must be a condition */
409 lua_remove(L, 1); /* remove it */
410 lua_pushliteral(L, "assertion failed!"); /* default message */
411 lua_settop(L, 1); /* leave only message (default if no other one) */
412 return luaB_error(L); /* call 'error' */
413 }
414}
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)
#define lua_remove(L, idx)
static int luaB_error(lua_State *L)

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

191 {
192 static const char *const opts[] = {"stop", "restart", "collect",
193 "count", "step", "setpause", "setstepmul",
194 "isrunning", "generational", "incremental", NULL};
195 static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
198 int o = optsnum[luaL_checkoption(L, 1, "collect", opts)];
199 switch (o) {
200 case LUA_GCCOUNT: {
201 int k = lua_gc(L, o);
202 int b = lua_gc(L, LUA_GCCOUNTB);
203 lua_pushnumber(L, (lua_Number)k + ((lua_Number)b/1024));
204 return 1;
205 }
206 case LUA_GCSTEP: {
207 int step = (int)luaL_optinteger(L, 2, 0);
208 int res = lua_gc(L, o, step);
209 lua_pushboolean(L, res);
210 return 1;
211 }
212 case LUA_GCSETPAUSE:
213 case LUA_GCSETSTEPMUL: {
214 int p = (int)luaL_optinteger(L, 2, 0);
215 int previous = lua_gc(L, o, p);
216 lua_pushinteger(L, previous);
217 return 1;
218 }
219 case LUA_GCISRUNNING: {
220 int res = lua_gc(L, o);
221 lua_pushboolean(L, res);
222 return 1;
223 }
224 case LUA_GCGEN: {
225 int minormul = (int)luaL_optinteger(L, 2, 0);
226 int majormul = (int)luaL_optinteger(L, 3, 0);
227 return pushmode(L, lua_gc(L, o, minormul, majormul));
228 }
229 case LUA_GCINC: {
230 int pause = (int)luaL_optinteger(L, 2, 0);
231 int stepmul = (int)luaL_optinteger(L, 3, 0);
232 int stepsize = (int)luaL_optinteger(L, 4, 0);
233 return pushmode(L, lua_gc(L, o, pause, stepmul, stepsize));
234 }
235 default: {
236 int res = lua_gc(L, o);
237 lua_pushinteger(L, res);
238 return 1;
239 }
240 }
241}
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_GCGEN
#define LUA_GCINC
#define LUA_GCISRUNNING
static int pushmode(lua_State *L, int oldmode)

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

◆ luaB_dofile()

static int luaB_dofile ( lua_State * L)
static

Definition at line 394 of file lua-5.4.3/src/lbaselib.c.

394 {
395 const char *fname = luaL_optstring(L, 1, NULL);
396 lua_settop(L, 1);
397 if (l_unlikely(luaL_loadfile(L, fname) != LUA_OK))
398 return lua_error(L);
400 return dofilecont(L, 0, 0);
401}
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 114 of file lua-5.4.3/src/lbaselib.c.

114 {
115 int level = (int)luaL_optinteger(L, 2, 1);
116 lua_settop(L, 1);
117 if (lua_type(L, 1) == LUA_TSTRING && level > 0) {
118 luaL_where(L, level); /* add extra information */
119 lua_pushvalue(L, 1);
120 lua_concat(L, 2);
121 }
122 return lua_error(L);
123}
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 126 of file lua-5.4.3/src/lbaselib.c.

126 {
127 luaL_checkany(L, 1);
128 if (!lua_getmetatable(L, 1)) {
129 lua_pushnil(L);
130 return 1; /* no metatable */
131 }
132 luaL_getmetafield(L, 1, "__metatable");
133 return 1; /* returns either __metatable field (if present) or metatable */
134}
LUA_API void lua_pushnil(lua_State *L)
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 293 of file lua-5.4.3/src/lbaselib.c.

293 {
294 luaL_checkany(L, 1);
295 lua_pushcfunction(L, ipairsaux); /* iteration function */
296 lua_pushvalue(L, 1); /* state */
297 lua_pushinteger(L, 0); /* initial value */
298 return 3;
299}
#define lua_pushcfunction(L, f)
static int ipairsaux(lua_State *L)

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

◆ luaB_load()

static int luaB_load ( lua_State * L)
static

Definition at line 366 of file lua-5.4.3/src/lbaselib.c.

366 {
367 int status;
368 size_t l;
369 const char *s = lua_tolstring(L, 1, &l);
370 const char *mode = luaL_optstring(L, 3, "bt");
371 int env = (!lua_isnone(L, 4) ? 4 : 0); /* 'env' index or 0 if no 'env' */
372 if (s != NULL) { /* loading a string? */
373 const char *chunkname = luaL_optstring(L, 2, s);
374 status = luaL_loadbufferx(L, s, l, chunkname, mode);
375 }
376 else { /* loading from a reader function */
377 const char *chunkname = luaL_optstring(L, 2, "=(load)");
379 lua_settop(L, RESERVEDSLOT); /* create reserved slot */
380 status = lua_load(L, generic_reader, NULL, chunkname, mode);
381 }
382 return load_aux(L, status, env);
383}
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 319 of file lua-5.4.3/src/lbaselib.c.

319 {
320 const char *fname = luaL_optstring(L, 1, NULL);
321 const char *mode = luaL_optstring(L, 2, NULL);
322 int env = (!lua_isnone(L, 3) ? 3 : 0); /* 'env' index or 0 if no 'env' */
323 int status = luaL_loadfilex(L, fname, mode);
324 return load_aux(L, status, env);
325}
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 252 of file lua-5.4.3/src/lbaselib.c.

252 {
254 lua_settop(L, 2); /* create a 2nd argument if there isn't one */
255 if (lua_next(L, 1))
256 return 2;
257 else {
258 lua_pushnil(L);
259 return 1;
260 }
261}
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 264 of file lua-5.4.3/src/lbaselib.c.

264 {
265 luaL_checkany(L, 1);
266 if (luaL_getmetafield(L, 1, "__pairs") == LUA_TNIL) { /* no metamethod? */
267 lua_pushcfunction(L, luaB_next); /* will return generator, */
268 lua_pushvalue(L, 1); /* state, */
269 lua_pushnil(L); /* and initial value */
270 }
271 else {
272 lua_pushvalue(L, 1); /* argument 'self' to metamethod */
273 lua_call(L, 1, 3); /* get 3 values from metamethod */
274 }
275 return 3;
276}
static int luaB_next(lua_State *L)

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

◆ luaB_pcall()

static int luaB_pcall ( lua_State * L)
static

Definition at line 451 of file lua-5.4.3/src/lbaselib.c.

451 {
452 int status;
453 luaL_checkany(L, 1);
454 lua_pushboolean(L, 1); /* first result if no errors */
455 lua_insert(L, 1); /* put it in place */
456 status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, finishpcall);
457 return finishpcall(L, status, 0);
458}
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.4.3/src/lbaselib.c.

24 {
25 int n = lua_gettop(L); /* number of arguments */
26 int i;
27 for (i = 1; i <= n; i++) { /* for each argument */
28 size_t l;
29 const char *s = luaL_tolstring(L, i, &l); /* convert it to string */
30 if (i > 1) /* not the first element? */
31 lua_writestring("\t", 1); /* add a tab before it */
32 lua_writestring(s, l); /* print it */
33 lua_pop(L, 1); /* pop result */
34 }
36 return 0;
37}
LUALIB_API const char * luaL_tolstring(lua_State *L, int idx, size_t *len)
#define lua_writestring(s, l)
#define lua_writeline()

References lua_gettop(), lua_pop, lua_writeline, lua_writestring, luaL_tolstring(), and s.

◆ luaB_rawequal()

static int luaB_rawequal ( lua_State * L)
static

Definition at line 149 of file lua-5.4.3/src/lbaselib.c.

149 {
150 luaL_checkany(L, 1);
151 luaL_checkany(L, 2);
152 lua_pushboolean(L, lua_rawequal(L, 1, 2));
153 return 1;
154}
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 166 of file lua-5.4.3/src/lbaselib.c.

166 {
168 luaL_checkany(L, 2);
169 lua_settop(L, 2);
170 lua_rawget(L, 1);
171 return 1;
172}
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 157 of file lua-5.4.3/src/lbaselib.c.

157 {
158 int t = lua_type(L, 1);
159 luaL_argexpected(L, t == LUA_TTABLE || t == LUA_TSTRING, 1,
160 "table or string");
161 lua_pushinteger(L, lua_rawlen(L, 1));
162 return 1;
163}
#define lua_rawlen(L, index)
Definition LuaXML_lib.c:42
#define luaL_argexpected(L, cond, arg, tname)

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

◆ luaB_rawset()

static int luaB_rawset ( lua_State * L)
static

Definition at line 174 of file lua-5.4.3/src/lbaselib.c.

174 {
176 luaL_checkany(L, 2);
177 luaL_checkany(L, 3);
178 lua_settop(L, 3);
179 lua_rawset(L, 1);
180 return 1;
181}
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 417 of file lua-5.4.3/src/lbaselib.c.

417 {
418 int n = lua_gettop(L);
419 if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {
420 lua_pushinteger(L, n-1);
421 return 1;
422 }
423 else {
425 if (i < 0) i = n + i;
426 else if (i > n) i = n;
427 luaL_argcheck(L, 1 <= i, 1, "index out of range");
428 return n - (int)i;
429 }
430}
#define luaL_argcheck(L, cond, numarg, extramsg)
#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 137 of file lua-5.4.3/src/lbaselib.c.

137 {
138 int t = lua_type(L, 2);
140 luaL_argexpected(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil or table");
141 if (l_unlikely(luaL_getmetafield(L, 1, "__metatable") != LUA_TNIL))
142 return luaL_error(L, "cannot change a protected metatable");
143 lua_settop(L, 2);
144 lua_setmetatable(L, 1);
145 return 1;
146}
LUA_API int lua_setmetatable(lua_State *L, int objindex)

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

◆ luaB_tonumber()

static int luaB_tonumber ( lua_State * L)
static

Definition at line 81 of file lua-5.4.3/src/lbaselib.c.

81 {
82 if (lua_isnoneornil(L, 2)) { /* standard conversion? */
83 if (lua_type(L, 1) == LUA_TNUMBER) { /* already a number? */
84 lua_settop(L, 1); /* yes; return it */
85 return 1;
86 }
87 else {
88 size_t l;
89 const char *s = lua_tolstring(L, 1, &l);
90 if (s != NULL && lua_stringtonumber(L, s) == l + 1)
91 return 1; /* successful conversion to number */
92 /* else not a number */
93 luaL_checkany(L, 1); /* (but there must be some parameter) */
94 }
95 }
96 else {
97 size_t l;
98 const char *s;
99 lua_Integer n = 0; /* to avoid warnings */
100 lua_Integer base = luaL_checkinteger(L, 2);
101 luaL_checktype(L, 1, LUA_TSTRING); /* no numbers as strings */
102 s = lua_tolstring(L, 1, &l);
103 luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
104 if (b_str2int(s, (int)base, &n) == s + l) {
105 lua_pushinteger(L, n);
106 return 1;
107 } /* else not a number */
108 } /* else not a number */
109 luaL_pushfail(L); /* not a number */
110 return 1;
111}
#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_settop(), lua_stringtonumber(), LUA_TNUMBER, lua_tolstring(), LUA_TSTRING, lua_type(), luaL_argcheck, luaL_checkany(), luaL_checkinteger(), luaL_checktype(), luaL_pushfail, NULL, and s.

◆ luaB_tostring()

static int luaB_tostring ( lua_State * L)
static

Definition at line 478 of file lua-5.4.3/src/lbaselib.c.

478 {
479 luaL_checkany(L, 1);
480 luaL_tolstring(L, 1, NULL);
481 return 1;
482}

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

◆ luaB_type()

static int luaB_type ( lua_State * L)
static

Definition at line 244 of file lua-5.4.3/src/lbaselib.c.

244 {
245 int t = lua_type(L, 1);
246 luaL_argcheck(L, t != LUA_TNONE, 1, "value expected");
248 return 1;
249}
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_warn()

static int luaB_warn ( lua_State * L)
static

Definition at line 45 of file lua-5.4.3/src/lbaselib.c.

45 {
46 int n = lua_gettop(L); /* number of arguments */
47 int i;
48 luaL_checkstring(L, 1); /* at least one argument */
49 for (i = 2; i <= n; i++)
50 luaL_checkstring(L, i); /* make sure all arguments are strings */
51 for (i = 1; i < n; i++) /* compose warning */
52 lua_warning(L, lua_tostring(L, i), 1);
53 lua_warning(L, lua_tostring(L, n), 0); /* close warning */
54 return 0;
55}
#define luaL_checkstring(L, n)
void lua_warning(lua_State *L, const char *msg, int tocont)

References lua_gettop(), lua_tostring, lua_warning(), and luaL_checkstring.

◆ luaB_xpcall()

static int luaB_xpcall ( lua_State * L)
static

Definition at line 466 of file lua-5.4.3/src/lbaselib.c.

466 {
467 int status;
468 int n = lua_gettop(L);
469 luaL_checktype(L, 2, LUA_TFUNCTION); /* check error function */
470 lua_pushboolean(L, 1); /* first result */
471 lua_pushvalue(L, 1); /* function */
472 lua_rotate(L, 3, 2); /* move them below function's arguments */
473 status = lua_pcallk(L, n - 2, LUA_MULTRET, 2, 2, finishpcall);
474 return finishpcall(L, status, 2);
475}
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 516 of file lua-5.4.3/src/lbaselib.c.

516 {
517 /* open lib into global table */
520 /* set global _G */
521 lua_pushvalue(L, -1);
522 lua_setfield(L, -2, LUA_GNAME);
523 /* set global _VERSION */
525 lua_setfield(L, -2, "_VERSION");
526 return 1;
527}
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)
#define LUA_GNAME
static const luaL_Reg base_funcs[]

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

◆ pushmode()

static int pushmode ( lua_State * L,
int oldmode )
static

Definition at line 184 of file lua-5.4.3/src/lbaselib.c.

184 {
185 lua_pushstring(L, (oldmode == LUA_GCINC) ? "incremental"
186 : "generational");
187 return 1;
188}

References LUA_GCINC, and lua_pushstring().

Referenced by luaB_collectgarbage().

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},
{"warn", luaB_warn},
{"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},
{"_VERSION", NULL},
}
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_warn(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 485 of file lua-5.4.3/src/lbaselib.c.

485 {
486 {"assert", luaB_assert},
487 {"collectgarbage", luaB_collectgarbage},
488 {"dofile", luaB_dofile},
489 {"error", luaB_error},
490 {"getmetatable", luaB_getmetatable},
491 {"ipairs", luaB_ipairs},
492 {"loadfile", luaB_loadfile},
493 {"load", luaB_load},
494 {"next", luaB_next},
495 {"pairs", luaB_pairs},
496 {"pcall", luaB_pcall},
497 {"print", luaB_print},
498 {"warn", luaB_warn},
499 {"rawequal", luaB_rawequal},
500 {"rawlen", luaB_rawlen},
501 {"rawget", luaB_rawget},
502 {"rawset", luaB_rawset},
503 {"select", luaB_select},
504 {"setmetatable", luaB_setmetatable},
505 {"tonumber", luaB_tonumber},
506 {"tostring", luaB_tostring},
507 {"type", luaB_type},
508 {"xpcall", luaB_xpcall},
509 /* placeholders */
510 {LUA_GNAME, NULL},
511 {"_VERSION", NULL},
512 {NULL, NULL}
513};

Referenced by luaopen_base().