Lines Matching full:l

24 static int luaB_print (lua_State *L) {  in luaB_print()  argument
25 int n = lua_gettop(L); /* number of arguments */ in luaB_print()
28 size_t l; in luaB_print() local
29 const char *s = luaL_tolstring(L, i, &l); /* convert it to string */ in luaB_print()
32 lua_writestring(s, l); /* print it */ in luaB_print()
33 lua_pop(L, 1); /* pop result */ in luaB_print()
45 static int luaB_warn (lua_State *L) { in luaB_warn() argument
46 int n = lua_gettop(L); /* number of arguments */ in luaB_warn()
48 luaL_checkstring(L, 1); /* at least one argument */ in luaB_warn()
50 luaL_checkstring(L, i); /* make sure all arguments are strings */ in luaB_warn()
52 lua_warning(L, lua_tostring(L, i), 1); in luaB_warn()
53 lua_warning(L, lua_tostring(L, n), 0); /* close warning */ in luaB_warn()
81 static int luaB_tonumber (lua_State *L) { in luaB_tonumber() argument
82 if (lua_isnoneornil(L, 2)) { /* standard conversion? */ in luaB_tonumber()
83 if (lua_type(L, 1) == LUA_TNUMBER) { /* already a number? */ in luaB_tonumber()
84 lua_settop(L, 1); /* yes; return it */ in luaB_tonumber()
88 size_t l; in luaB_tonumber() local
89 const char *s = lua_tolstring(L, 1, &l); in luaB_tonumber()
90 if (s != NULL && lua_stringtonumber(L, s) == l + 1) in luaB_tonumber()
93 luaL_checkany(L, 1); /* (but there must be some parameter) */ in luaB_tonumber()
97 size_t l; in luaB_tonumber() local
100 lua_Integer base = luaL_checkinteger(L, 2); in luaB_tonumber()
101 luaL_checktype(L, 1, LUA_TSTRING); /* no numbers as strings */ in luaB_tonumber()
102 s = lua_tolstring(L, 1, &l); in luaB_tonumber()
103 luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); in luaB_tonumber()
104 if (b_str2int(s, (int)base, &n) == s + l) { in luaB_tonumber()
105 lua_pushinteger(L, n); in luaB_tonumber()
109 luaL_pushfail(L); /* not a number */ in luaB_tonumber()
114 static int luaB_error (lua_State *L) { in luaB_error() argument
115 int level = (int)luaL_optinteger(L, 2, 1); in luaB_error()
116 lua_settop(L, 1); in luaB_error()
117 if (lua_type(L, 1) == LUA_TSTRING && level > 0) { in luaB_error()
118 luaL_where(L, level); /* add extra information */ in luaB_error()
119 lua_pushvalue(L, 1); in luaB_error()
120 lua_concat(L, 2); in luaB_error()
122 return lua_error(L); in luaB_error()
126 static int luaB_getmetatable (lua_State *L) { in luaB_getmetatable() argument
127 luaL_checkany(L, 1); in luaB_getmetatable()
128 if (!lua_getmetatable(L, 1)) { in luaB_getmetatable()
129 lua_pushnil(L); in luaB_getmetatable()
132 luaL_getmetafield(L, 1, "__metatable"); in luaB_getmetatable()
137 static int luaB_setmetatable (lua_State *L) { in luaB_setmetatable() argument
138 int t = lua_type(L, 2); in luaB_setmetatable()
139 luaL_checktype(L, 1, LUA_TTABLE); in luaB_setmetatable()
140 luaL_argexpected(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil or table"); in luaB_setmetatable()
141 if (l_unlikely(luaL_getmetafield(L, 1, "__metatable") != LUA_TNIL)) in luaB_setmetatable()
142 return luaL_error(L, "cannot change a protected metatable"); in luaB_setmetatable()
143 lua_settop(L, 2); in luaB_setmetatable()
144 lua_setmetatable(L, 1); in luaB_setmetatable()
149 static int luaB_rawequal (lua_State *L) { in luaB_rawequal() argument
150 luaL_checkany(L, 1); in luaB_rawequal()
151 luaL_checkany(L, 2); in luaB_rawequal()
152 lua_pushboolean(L, lua_rawequal(L, 1, 2)); in luaB_rawequal()
157 static int luaB_rawlen (lua_State *L) { in luaB_rawlen() argument
158 int t = lua_type(L, 1); in luaB_rawlen()
159 luaL_argexpected(L, t == LUA_TTABLE || t == LUA_TSTRING, 1, in luaB_rawlen()
161 lua_pushinteger(L, lua_rawlen(L, 1)); in luaB_rawlen()
166 static int luaB_rawget (lua_State *L) { in luaB_rawget() argument
167 luaL_checktype(L, 1, LUA_TTABLE); in luaB_rawget()
168 luaL_checkany(L, 2); in luaB_rawget()
169 lua_settop(L, 2); in luaB_rawget()
170 lua_rawget(L, 1); in luaB_rawget()
174 static int luaB_rawset (lua_State *L) { in luaB_rawset() argument
175 luaL_checktype(L, 1, LUA_TTABLE); in luaB_rawset()
176 luaL_checkany(L, 2); in luaB_rawset()
177 luaL_checkany(L, 3); in luaB_rawset()
178 lua_settop(L, 3); in luaB_rawset()
179 lua_rawset(L, 1); in luaB_rawset()
184 static int pushmode (lua_State *L, int oldmode) { in pushmode() argument
186 luaL_pushfail(L); /* invalid call to 'lua_gc' */ in pushmode()
188 lua_pushstring(L, (oldmode == LUA_GCINC) ? "incremental" in pushmode()
199 static int luaB_collectgarbage (lua_State *L) { in luaB_collectgarbage() argument
206 int o = optsnum[luaL_checkoption(L, 1, "collect", opts)]; in luaB_collectgarbage()
209 int k = lua_gc(L, o); in luaB_collectgarbage()
210 int b = lua_gc(L, LUA_GCCOUNTB); in luaB_collectgarbage()
212 lua_pushnumber(L, (lua_Number)k + ((lua_Number)b/1024)); in luaB_collectgarbage()
216 int step = (int)luaL_optinteger(L, 2, 0); in luaB_collectgarbage()
217 int res = lua_gc(L, o, step); in luaB_collectgarbage()
219 lua_pushboolean(L, res); in luaB_collectgarbage()
224 int p = (int)luaL_optinteger(L, 2, 0); in luaB_collectgarbage()
225 int previous = lua_gc(L, o, p); in luaB_collectgarbage()
227 lua_pushinteger(L, previous); in luaB_collectgarbage()
231 int res = lua_gc(L, o); in luaB_collectgarbage()
233 lua_pushboolean(L, res); in luaB_collectgarbage()
237 int minormul = (int)luaL_optinteger(L, 2, 0); in luaB_collectgarbage()
238 int majormul = (int)luaL_optinteger(L, 3, 0); in luaB_collectgarbage()
239 return pushmode(L, lua_gc(L, o, minormul, majormul)); in luaB_collectgarbage()
242 int pause = (int)luaL_optinteger(L, 2, 0); in luaB_collectgarbage()
243 int stepmul = (int)luaL_optinteger(L, 3, 0); in luaB_collectgarbage()
244 int stepsize = (int)luaL_optinteger(L, 4, 0); in luaB_collectgarbage()
245 return pushmode(L, lua_gc(L, o, pause, stepmul, stepsize)); in luaB_collectgarbage()
248 int res = lua_gc(L, o); in luaB_collectgarbage()
250 lua_pushinteger(L, res); in luaB_collectgarbage()
254 luaL_pushfail(L); /* invalid call (inside a finalizer) */ in luaB_collectgarbage()
259 static int luaB_type (lua_State *L) { in luaB_type() argument
260 int t = lua_type(L, 1); in luaB_type()
261 luaL_argcheck(L, t != LUA_TNONE, 1, "value expected"); in luaB_type()
262 lua_pushstring(L, lua_typename(L, t)); in luaB_type()
267 static int luaB_next (lua_State *L) { in luaB_next() argument
268 luaL_checktype(L, 1, LUA_TTABLE); in luaB_next()
269 lua_settop(L, 2); /* create a 2nd argument if there isn't one */ in luaB_next()
270 if (lua_next(L, 1)) in luaB_next()
273 lua_pushnil(L); in luaB_next()
279 static int pairscont (lua_State *L, int status, lua_KContext k) { in pairscont() argument
280 (void)L; (void)status; (void)k; /* unused */ in pairscont()
284 static int luaB_pairs (lua_State *L) { in luaB_pairs() argument
285 luaL_checkany(L, 1); in luaB_pairs()
286 if (luaL_getmetafield(L, 1, "__pairs") == LUA_TNIL) { /* no metamethod? */ in luaB_pairs()
287 lua_pushcfunction(L, luaB_next); /* will return generator, */ in luaB_pairs()
288 lua_pushvalue(L, 1); /* state, */ in luaB_pairs()
289 lua_pushnil(L); /* and initial value */ in luaB_pairs()
292 lua_pushvalue(L, 1); /* argument 'self' to metamethod */ in luaB_pairs()
293 lua_callk(L, 1, 3, 0, pairscont); /* get 3 values from metamethod */ in luaB_pairs()
302 static int ipairsaux (lua_State *L) { in ipairsaux() argument
303 lua_Integer i = luaL_checkinteger(L, 2); in ipairsaux()
305 lua_pushinteger(L, i); in ipairsaux()
306 return (lua_geti(L, 1, i) == LUA_TNIL) ? 1 : 2; in ipairsaux()
314 static int luaB_ipairs (lua_State *L) { in luaB_ipairs() argument
315 luaL_checkany(L, 1); in luaB_ipairs()
316 lua_pushcfunction(L, ipairsaux); /* iteration function */ in luaB_ipairs()
317 lua_pushvalue(L, 1); /* state */ in luaB_ipairs()
318 lua_pushinteger(L, 0); /* initial value */ in luaB_ipairs()
323 static int load_aux (lua_State *L, int status, int envidx) { in load_aux() argument
326 lua_pushvalue(L, envidx); /* environment for loaded function */ in load_aux()
327 if (!lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */ in load_aux()
328 lua_pop(L, 1); /* remove 'env' if not used by previous call */ in load_aux()
333 luaL_pushfail(L); in load_aux()
334 lua_insert(L, -2); /* put before error message */ in load_aux()
340 static int luaB_loadfile (lua_State *L) { in luaB_loadfile() argument
341 const char *fname = luaL_optstring(L, 1, NULL); in luaB_loadfile()
342 const char *mode = luaL_optstring(L, 2, NULL); in luaB_loadfile()
343 int env = (!lua_isnone(L, 3) ? 3 : 0); /* 'env' index or 0 if no 'env' */ in luaB_loadfile()
344 int status = luaL_loadfilex(L, fname, mode); in luaB_loadfile()
345 return load_aux(L, status, env); in luaB_loadfile()
370 static const char *generic_reader (lua_State *L, void *ud, size_t *size) { in generic_reader() argument
372 luaL_checkstack(L, 2, "too many nested functions"); in generic_reader()
373 lua_pushvalue(L, 1); /* get function */ in generic_reader()
374 lua_call(L, 0, 1); /* call it */ in generic_reader()
375 if (lua_isnil(L, -1)) { in generic_reader()
376 lua_pop(L, 1); /* pop result */ in generic_reader()
380 else if (l_unlikely(!lua_isstring(L, -1))) in generic_reader()
381 luaL_error(L, "reader function must return a string"); in generic_reader()
382 lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */ in generic_reader()
383 return lua_tolstring(L, RESERVEDSLOT, size); in generic_reader()
387 static int luaB_load (lua_State *L) { in luaB_load() argument
389 size_t l; in luaB_load() local
390 const char *s = lua_tolstring(L, 1, &l); in luaB_load()
391 const char *mode = luaL_optstring(L, 3, "bt"); in luaB_load()
392 int env = (!lua_isnone(L, 4) ? 4 : 0); /* 'env' index or 0 if no 'env' */ in luaB_load()
394 const char *chunkname = luaL_optstring(L, 2, s); in luaB_load()
395 status = luaL_loadbufferx(L, s, l, chunkname, mode); in luaB_load()
398 const char *chunkname = luaL_optstring(L, 2, "=(load)"); in luaB_load()
399 luaL_checktype(L, 1, LUA_TFUNCTION); in luaB_load()
400 lua_settop(L, RESERVEDSLOT); /* create reserved slot */ in luaB_load()
401 status = lua_load(L, generic_reader, NULL, chunkname, mode); in luaB_load()
403 return load_aux(L, status, env); in luaB_load()
409 static int dofilecont (lua_State *L, int d1, lua_KContext d2) { in dofilecont() argument
411 return lua_gettop(L) - 1; in dofilecont()
415 static int luaB_dofile (lua_State *L) { in luaB_dofile() argument
416 const char *fname = luaL_optstring(L, 1, NULL); in luaB_dofile()
417 lua_settop(L, 1); in luaB_dofile()
418 if (l_unlikely(luaL_loadfile(L, fname) != LUA_OK)) in luaB_dofile()
419 return lua_error(L); in luaB_dofile()
420 lua_callk(L, 0, LUA_MULTRET, 0, dofilecont); in luaB_dofile()
421 return dofilecont(L, 0, 0); in luaB_dofile()
425 static int luaB_assert (lua_State *L) { in luaB_assert() argument
426 if (l_likely(lua_toboolean(L, 1))) /* condition is true? */ in luaB_assert()
427 return lua_gettop(L); /* return all arguments */ in luaB_assert()
429 luaL_checkany(L, 1); /* there must be a condition */ in luaB_assert()
430 lua_remove(L, 1); /* remove it */ in luaB_assert()
431 lua_pushliteral(L, "assertion failed!"); /* default message */ in luaB_assert()
432 lua_settop(L, 1); /* leave only message (default if no other one) */ in luaB_assert()
433 return luaB_error(L); /* call 'error' */ in luaB_assert()
438 static int luaB_select (lua_State *L) { in luaB_select() argument
439 int n = lua_gettop(L); in luaB_select()
440 if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') { in luaB_select()
441 lua_pushinteger(L, n-1); in luaB_select()
445 lua_Integer i = luaL_checkinteger(L, 1); in luaB_select()
448 luaL_argcheck(L, 1 <= i, 1, "index out of range"); in luaB_select()
461 static int finishpcall (lua_State *L, int status, lua_KContext extra) { in finishpcall() argument
463 lua_pushboolean(L, 0); /* first result (false) */ in finishpcall()
464 lua_pushvalue(L, -2); /* error message */ in finishpcall()
468 return lua_gettop(L) - (int)extra; /* return all results */ in finishpcall()
472 static int luaB_pcall (lua_State *L) { in luaB_pcall() argument
474 luaL_checkany(L, 1); in luaB_pcall()
475 lua_pushboolean(L, 1); /* first result if no errors */ in luaB_pcall()
476 lua_insert(L, 1); /* put it in place */ in luaB_pcall()
477 status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, finishpcall); in luaB_pcall()
478 return finishpcall(L, status, 0); in luaB_pcall()
487 static int luaB_xpcall (lua_State *L) { in luaB_xpcall() argument
489 int n = lua_gettop(L); in luaB_xpcall()
490 luaL_checktype(L, 2, LUA_TFUNCTION); /* check error function */ in luaB_xpcall()
491 lua_pushboolean(L, 1); /* first result */ in luaB_xpcall()
492 lua_pushvalue(L, 1); /* function */ in luaB_xpcall()
493 lua_rotate(L, 3, 2); /* move them below function's arguments */ in luaB_xpcall()
494 status = lua_pcallk(L, n - 2, LUA_MULTRET, 2, 2, finishpcall); in luaB_xpcall()
495 return finishpcall(L, status, 2); in luaB_xpcall()
499 static int luaB_tostring (lua_State *L) { in luaB_tostring() argument
500 luaL_checkany(L, 1); in luaB_tostring()
501 luaL_tolstring(L, 1, NULL); in luaB_tostring()
537 LUAMOD_API int luaopen_base (lua_State *L) { in luaopen_base() argument
539 lua_pushglobaltable(L); in luaopen_base()
540 luaL_setfuncs(L, base_funcs, 0); in luaopen_base()
542 lua_pushvalue(L, -1); in luaopen_base()
543 lua_setfield(L, -2, LUA_GNAME); in luaopen_base()
545 lua_pushliteral(L, LUA_VERSION); in luaopen_base()
546 lua_setfield(L, -2, "_VERSION"); in luaopen_base()