• Home
  • Raw
  • Download

Lines Matching refs:L

23 static int luaB_print (lua_State *L) {  in luaB_print()  argument
24 int n = lua_gettop(L); /* number of arguments */ in luaB_print()
26 lua_getglobal(L, "tostring"); in luaB_print()
30 lua_pushvalue(L, -1); /* function to be called */ in luaB_print()
31 lua_pushvalue(L, i); /* value to print */ in luaB_print()
32 lua_call(L, 1, 1); in luaB_print()
33 s = lua_tolstring(L, -1, &l); /* get result */ in luaB_print()
35 return luaL_error(L, in luaB_print()
39 lua_pop(L, 1); /* pop result */ in luaB_print()
48 static int luaB_tonumber (lua_State *L) { in luaB_tonumber() argument
49 if (lua_isnoneornil(L, 2)) { /* standard conversion */ in luaB_tonumber()
51 lua_Number n = lua_tonumberx(L, 1, &isnum); in luaB_tonumber()
53 lua_pushnumber(L, n); in luaB_tonumber()
56 luaL_checkany(L, 1); in luaB_tonumber()
60 const char *s = luaL_checklstring(L, 1, &l); in luaB_tonumber()
62 int base = luaL_checkint(L, 2); in luaB_tonumber()
64 luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); in luaB_tonumber()
79 lua_pushnumber(L, (neg) ? -n : n); in luaB_tonumber()
84 lua_pushnil(L); /* not a number */ in luaB_tonumber()
89 static int luaB_error (lua_State *L) { in luaB_error() argument
90 int level = luaL_optint(L, 2, 1); in luaB_error()
91 lua_settop(L, 1); in luaB_error()
92 if (lua_isstring(L, 1) && level > 0) { /* add extra information? */ in luaB_error()
93 luaL_where(L, level); in luaB_error()
94 lua_pushvalue(L, 1); in luaB_error()
95 lua_concat(L, 2); in luaB_error()
97 return lua_error(L); in luaB_error()
101 static int luaB_getmetatable (lua_State *L) { in luaB_getmetatable() argument
102 luaL_checkany(L, 1); in luaB_getmetatable()
103 if (!lua_getmetatable(L, 1)) { in luaB_getmetatable()
104 lua_pushnil(L); in luaB_getmetatable()
107 luaL_getmetafield(L, 1, "__metatable"); in luaB_getmetatable()
112 static int luaB_setmetatable (lua_State *L) { in luaB_setmetatable() argument
113 int t = lua_type(L, 2); in luaB_setmetatable()
114 luaL_checktype(L, 1, LUA_TTABLE); in luaB_setmetatable()
115 luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, in luaB_setmetatable()
117 if (luaL_getmetafield(L, 1, "__metatable")) in luaB_setmetatable()
118 return luaL_error(L, "cannot change a protected metatable"); in luaB_setmetatable()
119 lua_settop(L, 2); in luaB_setmetatable()
120 lua_setmetatable(L, 1); in luaB_setmetatable()
125 static int luaB_rawequal (lua_State *L) { in luaB_rawequal() argument
126 luaL_checkany(L, 1); in luaB_rawequal()
127 luaL_checkany(L, 2); in luaB_rawequal()
128 lua_pushboolean(L, lua_rawequal(L, 1, 2)); in luaB_rawequal()
133 static int luaB_rawlen (lua_State *L) { in luaB_rawlen() argument
134 int t = lua_type(L, 1); in luaB_rawlen()
135 luaL_argcheck(L, t == LUA_TTABLE || t == LUA_TSTRING, 1, in luaB_rawlen()
137 lua_pushinteger(L, lua_rawlen(L, 1)); in luaB_rawlen()
142 static int luaB_rawget (lua_State *L) { in luaB_rawget() argument
143 luaL_checktype(L, 1, LUA_TTABLE); in luaB_rawget()
144 luaL_checkany(L, 2); in luaB_rawget()
145 lua_settop(L, 2); in luaB_rawget()
146 lua_rawget(L, 1); in luaB_rawget()
150 static int luaB_rawset (lua_State *L) { in luaB_rawset() argument
151 luaL_checktype(L, 1, LUA_TTABLE); in luaB_rawset()
152 luaL_checkany(L, 2); in luaB_rawset()
153 luaL_checkany(L, 3); in luaB_rawset()
154 lua_settop(L, 3); in luaB_rawset()
155 lua_rawset(L, 1); in luaB_rawset()
160 static int luaB_collectgarbage (lua_State *L) { in luaB_collectgarbage() argument
167 int o = optsnum[luaL_checkoption(L, 1, "collect", opts)]; in luaB_collectgarbage()
168 int ex = luaL_optint(L, 2, 0); in luaB_collectgarbage()
169 int res = lua_gc(L, o, ex); in luaB_collectgarbage()
172 int b = lua_gc(L, LUA_GCCOUNTB, 0); in luaB_collectgarbage()
173 lua_pushnumber(L, res + ((lua_Number)b/1024)); in luaB_collectgarbage()
174 lua_pushinteger(L, b); in luaB_collectgarbage()
178 lua_pushboolean(L, res); in luaB_collectgarbage()
182 lua_pushinteger(L, res); in luaB_collectgarbage()
189 static int luaB_type (lua_State *L) { in luaB_type() argument
190 luaL_checkany(L, 1); in luaB_type()
191 lua_pushstring(L, luaL_typename(L, 1)); in luaB_type()
196 static int pairsmeta (lua_State *L, const char *method, int iszero, in pairsmeta() argument
198 if (!luaL_getmetafield(L, 1, method)) { /* no metamethod? */ in pairsmeta()
199 luaL_checktype(L, 1, LUA_TTABLE); /* argument must be a table */ in pairsmeta()
200 lua_pushcfunction(L, iter); /* will return generator, */ in pairsmeta()
201 lua_pushvalue(L, 1); /* state, */ in pairsmeta()
202 if (iszero) lua_pushinteger(L, 0); /* and initial value */ in pairsmeta()
203 else lua_pushnil(L); in pairsmeta()
206 lua_pushvalue(L, 1); /* argument 'self' to metamethod */ in pairsmeta()
207 lua_call(L, 1, 3); /* get 3 values from metamethod */ in pairsmeta()
213 static int luaB_next (lua_State *L) { in luaB_next() argument
214 luaL_checktype(L, 1, LUA_TTABLE); in luaB_next()
215 lua_settop(L, 2); /* create a 2nd argument if there isn't one */ in luaB_next()
216 if (lua_next(L, 1)) in luaB_next()
219 lua_pushnil(L); in luaB_next()
225 static int luaB_pairs (lua_State *L) { in luaB_pairs() argument
226 return pairsmeta(L, "__pairs", 0, luaB_next); in luaB_pairs()
230 static int ipairsaux (lua_State *L) { in ipairsaux() argument
231 int i = luaL_checkint(L, 2); in ipairsaux()
232 luaL_checktype(L, 1, LUA_TTABLE); in ipairsaux()
234 lua_pushinteger(L, i); in ipairsaux()
235 lua_rawgeti(L, 1, i); in ipairsaux()
236 return (lua_isnil(L, -1)) ? 1 : 2; in ipairsaux()
240 static int luaB_ipairs (lua_State *L) { in luaB_ipairs() argument
241 return pairsmeta(L, "__ipairs", 1, ipairsaux); in luaB_ipairs()
245 static int load_aux (lua_State *L, int status, int envidx) { in load_aux() argument
248 lua_pushvalue(L, envidx); /* environment for loaded function */ in load_aux()
249 if (!lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */ in load_aux()
250 lua_pop(L, 1); /* remove 'env' if not used by previous call */ in load_aux()
255 lua_pushnil(L); in load_aux()
256 lua_insert(L, -2); /* put before error message */ in load_aux()
262 static int luaB_loadfile (lua_State *L) { in luaB_loadfile() argument
263 const char *fname = luaL_optstring(L, 1, NULL); in luaB_loadfile()
264 const char *mode = luaL_optstring(L, 2, NULL); in luaB_loadfile()
265 int env = (!lua_isnone(L, 3) ? 3 : 0); /* 'env' index or 0 if no 'env' */ in luaB_loadfile()
266 int status = luaL_loadfilex(L, fname, mode); in luaB_loadfile()
267 return load_aux(L, status, env); in luaB_loadfile()
292 static const char *generic_reader (lua_State *L, void *ud, size_t *size) { in generic_reader() argument
294 luaL_checkstack(L, 2, "too many nested functions"); in generic_reader()
295 lua_pushvalue(L, 1); /* get function */ in generic_reader()
296 lua_call(L, 0, 1); /* call it */ in generic_reader()
297 if (lua_isnil(L, -1)) { in generic_reader()
298 lua_pop(L, 1); /* pop result */ in generic_reader()
302 else if (!lua_isstring(L, -1)) in generic_reader()
303 luaL_error(L, "reader function must return a string"); in generic_reader()
304 lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */ in generic_reader()
305 return lua_tolstring(L, RESERVEDSLOT, size); in generic_reader()
309 static int luaB_load (lua_State *L) { in luaB_load() argument
312 const char *s = lua_tolstring(L, 1, &l); in luaB_load()
313 const char *mode = luaL_optstring(L, 3, "bt"); in luaB_load()
314 int env = (!lua_isnone(L, 4) ? 4 : 0); /* 'env' index or 0 if no 'env' */ in luaB_load()
316 const char *chunkname = luaL_optstring(L, 2, s); in luaB_load()
317 status = luaL_loadbufferx(L, s, l, chunkname, mode); in luaB_load()
320 const char *chunkname = luaL_optstring(L, 2, "=(load)"); in luaB_load()
321 luaL_checktype(L, 1, LUA_TFUNCTION); in luaB_load()
322 lua_settop(L, RESERVEDSLOT); /* create reserved slot */ in luaB_load()
323 status = lua_load(L, generic_reader, NULL, chunkname, mode); in luaB_load()
325 return load_aux(L, status, env); in luaB_load()
331 static int dofilecont (lua_State *L) { in dofilecont() argument
332 return lua_gettop(L) - 1; in dofilecont()
336 static int luaB_dofile (lua_State *L) { in luaB_dofile() argument
337 const char *fname = luaL_optstring(L, 1, NULL); in luaB_dofile()
338 lua_settop(L, 1); in luaB_dofile()
339 if (luaL_loadfile(L, fname) != LUA_OK) in luaB_dofile()
340 return lua_error(L); in luaB_dofile()
341 lua_callk(L, 0, LUA_MULTRET, 0, dofilecont); in luaB_dofile()
342 return dofilecont(L); in luaB_dofile()
346 static int luaB_assert (lua_State *L) { in luaB_assert() argument
347 if (!lua_toboolean(L, 1)) in luaB_assert()
348 return luaL_error(L, "%s", luaL_optstring(L, 2, "assertion failed!")); in luaB_assert()
349 return lua_gettop(L); in luaB_assert()
353 static int luaB_select (lua_State *L) { in luaB_select() argument
354 int n = lua_gettop(L); in luaB_select()
355 if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') { in luaB_select()
356 lua_pushinteger(L, n-1); in luaB_select()
360 int i = luaL_checkint(L, 1); in luaB_select()
363 luaL_argcheck(L, 1 <= i, 1, "index out of range"); in luaB_select()
369 static int finishpcall (lua_State *L, int status) { in finishpcall() argument
370 if (!lua_checkstack(L, 1)) { /* no space for extra boolean? */ in finishpcall()
371 lua_settop(L, 0); /* create space for return values */ in finishpcall()
372 lua_pushboolean(L, 0); in finishpcall()
373 lua_pushstring(L, "stack overflow"); in finishpcall()
376 lua_pushboolean(L, status); /* first result (status) */ in finishpcall()
377 lua_replace(L, 1); /* put first result in first slot */ in finishpcall()
378 return lua_gettop(L); in finishpcall()
382 static int pcallcont (lua_State *L) { in pcallcont() argument
383 int status = lua_getctx(L, NULL); in pcallcont()
384 return finishpcall(L, (status == LUA_YIELD)); in pcallcont()
388 static int luaB_pcall (lua_State *L) { in luaB_pcall() argument
390 luaL_checkany(L, 1); in luaB_pcall()
391 lua_pushnil(L); in luaB_pcall()
392 lua_insert(L, 1); /* create space for status result */ in luaB_pcall()
393 status = lua_pcallk(L, lua_gettop(L) - 2, LUA_MULTRET, 0, 0, pcallcont); in luaB_pcall()
394 return finishpcall(L, (status == LUA_OK)); in luaB_pcall()
398 static int luaB_xpcall (lua_State *L) { in luaB_xpcall() argument
400 int n = lua_gettop(L); in luaB_xpcall()
401 luaL_argcheck(L, n >= 2, 2, "value expected"); in luaB_xpcall()
402 lua_pushvalue(L, 1); /* exchange function... */ in luaB_xpcall()
403 lua_copy(L, 2, 1); /* ...and error handler */ in luaB_xpcall()
404 lua_replace(L, 2); in luaB_xpcall()
405 status = lua_pcallk(L, n - 2, LUA_MULTRET, 1, 0, pcallcont); in luaB_xpcall()
406 return finishpcall(L, (status == LUA_OK)); in luaB_xpcall()
410 static int luaB_tostring (lua_State *L) { in luaB_tostring() argument
411 luaL_checkany(L, 1); in luaB_tostring()
412 luaL_tolstring(L, 1, NULL); in luaB_tostring()
447 LUAMOD_API int luaopen_base (lua_State *L) { in luaopen_base() argument
449 lua_pushglobaltable(L); in luaopen_base()
450 lua_pushglobaltable(L); in luaopen_base()
451 lua_setfield(L, -2, "_G"); in luaopen_base()
453 luaL_setfuncs(L, base_funcs, 0); in luaopen_base()
454 lua_pushliteral(L, LUA_VERSION); in luaopen_base()
455 lua_setfield(L, -2, "_VERSION"); /* set global _VERSION */ in luaopen_base()