Lines Matching refs: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()
29 const char *s = luaL_tolstring(L, i, &l); /* convert it to string */ 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()
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()
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()
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 (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
185 lua_pushstring(L, (oldmode == LUA_GCINC) ? "incremental" : "generational"); in pushmode()
190 static int luaB_collectgarbage (lua_State *L) { in luaB_collectgarbage() argument
197 int o = optsnum[luaL_checkoption(L, 1, "collect", opts)]; in luaB_collectgarbage()
200 int k = lua_gc(L, o); in luaB_collectgarbage()
201 int b = lua_gc(L, LUA_GCCOUNTB); in luaB_collectgarbage()
202 lua_pushnumber(L, (lua_Number)k + ((lua_Number)b/1024)); in luaB_collectgarbage()
206 int step = (int)luaL_optinteger(L, 2, 0); in luaB_collectgarbage()
207 int res = lua_gc(L, o, step); in luaB_collectgarbage()
208 lua_pushboolean(L, res); in luaB_collectgarbage()
213 int p = (int)luaL_optinteger(L, 2, 0); in luaB_collectgarbage()
214 int previous = lua_gc(L, o, p); in luaB_collectgarbage()
215 lua_pushinteger(L, previous); in luaB_collectgarbage()
219 int res = lua_gc(L, o); in luaB_collectgarbage()
220 lua_pushboolean(L, res); in luaB_collectgarbage()
224 int minormul = (int)luaL_optinteger(L, 2, 0); in luaB_collectgarbage()
225 int majormul = (int)luaL_optinteger(L, 3, 0); in luaB_collectgarbage()
226 return pushmode(L, lua_gc(L, o, minormul, majormul)); in luaB_collectgarbage()
229 int pause = (int)luaL_optinteger(L, 2, 0); in luaB_collectgarbage()
230 int stepmul = (int)luaL_optinteger(L, 3, 0); in luaB_collectgarbage()
231 int stepsize = (int)luaL_optinteger(L, 4, 0); in luaB_collectgarbage()
232 return pushmode(L, lua_gc(L, o, pause, stepmul, stepsize)); in luaB_collectgarbage()
235 int res = lua_gc(L, o); in luaB_collectgarbage()
236 lua_pushinteger(L, res); in luaB_collectgarbage()
243 static int luaB_type (lua_State *L) { in luaB_type() argument
244 int t = lua_type(L, 1); in luaB_type()
245 luaL_argcheck(L, t != LUA_TNONE, 1, "value expected"); in luaB_type()
246 lua_pushstring(L, lua_typename(L, t)); in luaB_type()
251 static int luaB_next (lua_State *L) { in luaB_next() argument
252 luaL_checktype(L, 1, LUA_TTABLE); in luaB_next()
253 lua_settop(L, 2); /* create a 2nd argument if there isn't one */ in luaB_next()
254 if (lua_next(L, 1)) in luaB_next()
257 lua_pushnil(L); in luaB_next()
263 static int luaB_pairs (lua_State *L) { in luaB_pairs() argument
264 luaL_checkany(L, 1); in luaB_pairs()
265 if (luaL_getmetafield(L, 1, "__pairs") == LUA_TNIL) { /* no metamethod? */ in luaB_pairs()
266 lua_pushcfunction(L, luaB_next); /* will return generator, */ in luaB_pairs()
267 lua_pushvalue(L, 1); /* state, */ in luaB_pairs()
268 lua_pushnil(L); /* and initial value */ in luaB_pairs()
271 lua_pushvalue(L, 1); /* argument 'self' to metamethod */ in luaB_pairs()
272 lua_call(L, 1, 3); /* get 3 values from metamethod */ in luaB_pairs()
281 static int ipairsaux (lua_State *L) { in ipairsaux() argument
282 lua_Integer i = luaL_checkinteger(L, 2) + 1; in ipairsaux()
283 lua_pushinteger(L, i); in ipairsaux()
284 return (lua_geti(L, 1, i) == LUA_TNIL) ? 1 : 2; in ipairsaux()
292 static int luaB_ipairs (lua_State *L) { in luaB_ipairs() argument
293 luaL_checkany(L, 1); in luaB_ipairs()
294 lua_pushcfunction(L, ipairsaux); /* iteration function */ in luaB_ipairs()
295 lua_pushvalue(L, 1); /* state */ in luaB_ipairs()
296 lua_pushinteger(L, 0); /* initial value */ in luaB_ipairs()
301 static int load_aux (lua_State *L, int status, int envidx) { in load_aux() argument
304 lua_pushvalue(L, envidx); /* environment for loaded function */ in load_aux()
305 if (!lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */ in load_aux()
306 lua_pop(L, 1); /* remove 'env' if not used by previous call */ in load_aux()
311 luaL_pushfail(L); in load_aux()
312 lua_insert(L, -2); /* put before error message */ in load_aux()
318 static int luaB_loadfile (lua_State *L) { in luaB_loadfile() argument
319 const char *fname = luaL_optstring(L, 1, NULL); in luaB_loadfile()
320 const char *mode = luaL_optstring(L, 2, NULL); in luaB_loadfile()
321 int env = (!lua_isnone(L, 3) ? 3 : 0); /* 'env' index or 0 if no 'env' */ in luaB_loadfile()
322 int status = luaL_loadfilex(L, fname, mode); in luaB_loadfile()
323 return load_aux(L, status, env); in luaB_loadfile()
348 static const char *generic_reader (lua_State *L, void *ud, size_t *size) { in generic_reader() argument
350 luaL_checkstack(L, 2, "too many nested functions"); in generic_reader()
351 lua_pushvalue(L, 1); /* get function */ in generic_reader()
352 lua_call(L, 0, 1); /* call it */ in generic_reader()
353 if (lua_isnil(L, -1)) { in generic_reader()
354 lua_pop(L, 1); /* pop result */ in generic_reader()
358 else if (!lua_isstring(L, -1)) in generic_reader()
359 luaL_error(L, "reader function must return a string"); in generic_reader()
360 lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */ in generic_reader()
361 return lua_tolstring(L, RESERVEDSLOT, size); in generic_reader()
365 static int luaB_load (lua_State *L) { in luaB_load() argument
368 const char *s = lua_tolstring(L, 1, &l); in luaB_load()
369 const char *mode = luaL_optstring(L, 3, "bt"); in luaB_load()
370 int env = (!lua_isnone(L, 4) ? 4 : 0); /* 'env' index or 0 if no 'env' */ in luaB_load()
372 const char *chunkname = luaL_optstring(L, 2, s); in luaB_load()
373 status = luaL_loadbufferx(L, s, l, chunkname, mode); in luaB_load()
376 const char *chunkname = luaL_optstring(L, 2, "=(load)"); in luaB_load()
377 luaL_checktype(L, 1, LUA_TFUNCTION); in luaB_load()
378 lua_settop(L, RESERVEDSLOT); /* create reserved slot */ in luaB_load()
379 status = lua_load(L, generic_reader, NULL, chunkname, mode); in luaB_load()
381 return load_aux(L, status, env); in luaB_load()
387 static int dofilecont (lua_State *L, int d1, lua_KContext d2) { in dofilecont() argument
389 return lua_gettop(L) - 1; in dofilecont()
393 static int luaB_dofile (lua_State *L) { in luaB_dofile() argument
394 const char *fname = luaL_optstring(L, 1, NULL); in luaB_dofile()
395 lua_settop(L, 1); in luaB_dofile()
396 if (luaL_loadfile(L, fname) != LUA_OK) in luaB_dofile()
397 return lua_error(L); in luaB_dofile()
398 lua_callk(L, 0, LUA_MULTRET, 0, dofilecont); in luaB_dofile()
399 return dofilecont(L, 0, 0); in luaB_dofile()
403 static int luaB_assert (lua_State *L) { in luaB_assert() argument
404 if (lua_toboolean(L, 1)) /* condition is true? */ in luaB_assert()
405 return lua_gettop(L); /* return all arguments */ in luaB_assert()
407 luaL_checkany(L, 1); /* there must be a condition */ in luaB_assert()
408 lua_remove(L, 1); /* remove it */ in luaB_assert()
409 lua_pushliteral(L, "assertion failed!"); /* default message */ in luaB_assert()
410 lua_settop(L, 1); /* leave only message (default if no other one) */ in luaB_assert()
411 return luaB_error(L); /* call 'error' */ in luaB_assert()
416 static int luaB_select (lua_State *L) { in luaB_select() argument
417 int n = lua_gettop(L); in luaB_select()
418 if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') { in luaB_select()
419 lua_pushinteger(L, n-1); in luaB_select()
423 lua_Integer i = luaL_checkinteger(L, 1); in luaB_select()
426 luaL_argcheck(L, 1 <= i, 1, "index out of range"); in luaB_select()
439 static int finishpcall (lua_State *L, int status, lua_KContext extra) { in finishpcall() argument
441 lua_pushboolean(L, 0); /* first result (false) */ in finishpcall()
442 lua_pushvalue(L, -2); /* error message */ in finishpcall()
446 return lua_gettop(L) - (int)extra; /* return all results */ in finishpcall()
450 static int luaB_pcall (lua_State *L) { in luaB_pcall() argument
452 luaL_checkany(L, 1); in luaB_pcall()
453 lua_pushboolean(L, 1); /* first result if no errors */ in luaB_pcall()
454 lua_insert(L, 1); /* put it in place */ in luaB_pcall()
455 status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, finishpcall); in luaB_pcall()
456 return finishpcall(L, status, 0); in luaB_pcall()
465 static int luaB_xpcall (lua_State *L) { in luaB_xpcall() argument
467 int n = lua_gettop(L); in luaB_xpcall()
468 luaL_checktype(L, 2, LUA_TFUNCTION); /* check error function */ in luaB_xpcall()
469 lua_pushboolean(L, 1); /* first result */ in luaB_xpcall()
470 lua_pushvalue(L, 1); /* function */ in luaB_xpcall()
471 lua_rotate(L, 3, 2); /* move them below function's arguments */ in luaB_xpcall()
472 status = lua_pcallk(L, n - 2, LUA_MULTRET, 2, 2, finishpcall); in luaB_xpcall()
473 return finishpcall(L, status, 2); in luaB_xpcall()
477 static int luaB_tostring (lua_State *L) { in luaB_tostring() argument
478 luaL_checkany(L, 1); in luaB_tostring()
479 luaL_tolstring(L, 1, NULL); in luaB_tostring()
515 LUAMOD_API int luaopen_base (lua_State *L) { in luaopen_base() argument
517 lua_pushglobaltable(L); in luaopen_base()
518 luaL_setfuncs(L, base_funcs, 0); in luaopen_base()
520 lua_pushvalue(L, -1); in luaopen_base()
521 lua_setfield(L, -2, LUA_GNAME); in luaopen_base()
523 lua_pushliteral(L, LUA_VERSION); in luaopen_base()
524 lua_setfield(L, -2, "_VERSION"); in luaopen_base()