Lines Matching refs:L

38 static int findfield (lua_State *L, int objidx, int level) {  in findfield()  argument
39 if (level == 0 || !lua_istable(L, -1)) in findfield()
41 lua_pushnil(L); /* start 'next' loop */ in findfield()
42 while (lua_next(L, -2)) { /* for each pair in table */ in findfield()
43 if (lua_type(L, -2) == LUA_TSTRING) { /* ignore non-string keys */ in findfield()
44 if (lua_rawequal(L, objidx, -1)) { /* found object? */ in findfield()
45 lua_pop(L, 1); /* remove value (but keep name) */ in findfield()
48 else if (findfield(L, objidx, level - 1)) { /* try recursively */ in findfield()
49 lua_remove(L, -2); /* remove table (but keep name) */ in findfield()
50 lua_pushliteral(L, "."); in findfield()
51 lua_insert(L, -2); /* place '.' between the two names */ in findfield()
52 lua_concat(L, 3); in findfield()
56 lua_pop(L, 1); /* remove value */ in findfield()
62 static int pushglobalfuncname (lua_State *L, lua_Debug *ar) { in pushglobalfuncname() argument
63 int top = lua_gettop(L); in pushglobalfuncname()
64 lua_getinfo(L, "f", ar); /* push function */ in pushglobalfuncname()
65 lua_pushglobaltable(L); in pushglobalfuncname()
66 if (findfield(L, top + 1, 2)) { in pushglobalfuncname()
67 lua_copy(L, -1, top + 1); /* move name to proper place */ in pushglobalfuncname()
68 lua_pop(L, 2); /* remove pushed values */ in pushglobalfuncname()
72 lua_settop(L, top); /* remove function and global table */ in pushglobalfuncname()
78 static void pushfuncname (lua_State *L, lua_Debug *ar) { in pushfuncname() argument
80 lua_pushfstring(L, "function " LUA_QS, ar->name); in pushfuncname()
82 lua_pushliteral(L, "main chunk"); in pushfuncname()
84 if (pushglobalfuncname(L, ar)) { in pushfuncname()
85 lua_pushfstring(L, "function " LUA_QS, lua_tostring(L, -1)); in pushfuncname()
86 lua_remove(L, -2); /* remove name */ in pushfuncname()
89 lua_pushliteral(L, "?"); in pushfuncname()
92 lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined); in pushfuncname()
96 static int countlevels (lua_State *L) { in countlevels() argument
100 while (lua_getstack(L, le, &ar)) { li = le; le *= 2; } in countlevels()
104 if (lua_getstack(L, m, &ar)) li = m + 1; in countlevels()
111 LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, in luaL_traceback() argument
114 int top = lua_gettop(L); in luaL_traceback()
117 if (msg) lua_pushfstring(L, "%s\n", msg); in luaL_traceback()
118 lua_pushliteral(L, "stack traceback:"); in luaL_traceback()
121 lua_pushliteral(L, "\n\t..."); /* add a '...' */ in luaL_traceback()
126 lua_pushfstring(L, "\n\t%s:", ar.short_src); in luaL_traceback()
128 lua_pushfstring(L, "%d:", ar.currentline); in luaL_traceback()
129 lua_pushliteral(L, " in "); in luaL_traceback()
130 pushfuncname(L, &ar); in luaL_traceback()
132 lua_pushliteral(L, "\n\t(...tail calls...)"); in luaL_traceback()
133 lua_concat(L, lua_gettop(L) - top); in luaL_traceback()
136 lua_concat(L, lua_gettop(L) - top); in luaL_traceback()
148 LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { in luaL_argerror() argument
150 if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ in luaL_argerror()
151 return luaL_error(L, "bad argument #%d (%s)", narg, extramsg); in luaL_argerror()
152 lua_getinfo(L, "n", &ar); in luaL_argerror()
156 return luaL_error(L, "calling " LUA_QS " on bad self (%s)", in luaL_argerror()
160 ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?"; in luaL_argerror()
161 return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)", in luaL_argerror()
166 static int typeerror (lua_State *L, int narg, const char *tname) { in typeerror() argument
167 const char *msg = lua_pushfstring(L, "%s expected, got %s", in typeerror()
168 tname, luaL_typename(L, narg)); in typeerror()
169 return luaL_argerror(L, narg, msg); in typeerror()
173 static void tag_error (lua_State *L, int narg, int tag) { in tag_error() argument
174 typeerror(L, narg, lua_typename(L, tag)); in tag_error()
178 LUALIB_API void luaL_where (lua_State *L, int level) { in luaL_where() argument
180 if (lua_getstack(L, level, &ar)) { /* check function at level */ in luaL_where()
181 lua_getinfo(L, "Sl", &ar); /* get info about it */ in luaL_where()
183 lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline); in luaL_where()
187 lua_pushliteral(L, ""); /* else, no information available... */ in luaL_where()
191 LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { in luaL_error() argument
194 luaL_where(L, 1); in luaL_error()
195 lua_pushvfstring(L, fmt, argp); in luaL_error()
197 lua_concat(L, 2); in luaL_error()
198 return lua_error(L); in luaL_error()
233 LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { in luaL_newmetatable() argument
234 luaL_getmetatable(L, tname); /* try to get metatable */ in luaL_newmetatable()
235 if (!lua_isnil(L, -1)) /* name already in use? */ in luaL_newmetatable()
237 lua_pop(L, 1); in luaL_newmetatable()
238 lua_newtable(L); /* create metatable */ in luaL_newmetatable()
239 lua_pushvalue(L, -1); in luaL_newmetatable()
240 lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */ in luaL_newmetatable()
245 LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) { in luaL_setmetatable() argument
246 luaL_getmetatable(L, tname); in luaL_setmetatable()
247 lua_setmetatable(L, -2); in luaL_setmetatable()
251 LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { in luaL_testudata() argument
252 void *p = lua_touserdata(L, ud); in luaL_testudata()
254 if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ in luaL_testudata()
255 luaL_getmetatable(L, tname); /* get correct metatable */ in luaL_testudata()
256 if (!lua_rawequal(L, -1, -2)) /* not the same? */ in luaL_testudata()
258 lua_pop(L, 2); /* remove both metatables */ in luaL_testudata()
266 LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { in luaL_checkudata() argument
267 void *p = luaL_testudata(L, ud, tname); in luaL_checkudata()
268 if (p == NULL) typeerror(L, ud, tname); in luaL_checkudata()
281 LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, in luaL_checkoption() argument
283 const char *name = (def) ? luaL_optstring(L, narg, def) : in luaL_checkoption()
284 luaL_checkstring(L, narg); in luaL_checkoption()
289 return luaL_argerror(L, narg, in luaL_checkoption()
290 lua_pushfstring(L, "invalid option " LUA_QS, name)); in luaL_checkoption()
294 LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg) { in luaL_checkstack() argument
297 if (!lua_checkstack(L, space + extra)) { in luaL_checkstack()
299 luaL_error(L, "stack overflow (%s)", msg); in luaL_checkstack()
301 luaL_error(L, "stack overflow"); in luaL_checkstack()
306 LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) { in luaL_checktype() argument
307 if (lua_type(L, narg) != t) in luaL_checktype()
308 tag_error(L, narg, t); in luaL_checktype()
312 LUALIB_API void luaL_checkany (lua_State *L, int narg) { in luaL_checkany() argument
313 if (lua_type(L, narg) == LUA_TNONE) in luaL_checkany()
314 luaL_argerror(L, narg, "value expected"); in luaL_checkany()
318 LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { in luaL_checklstring() argument
319 const char *s = lua_tolstring(L, narg, len); in luaL_checklstring()
320 if (!s) tag_error(L, narg, LUA_TSTRING); in luaL_checklstring()
325 LUALIB_API const char *luaL_optlstring (lua_State *L, int narg, in luaL_optlstring() argument
327 if (lua_isnoneornil(L, narg)) { in luaL_optlstring()
332 else return luaL_checklstring(L, narg, len); in luaL_optlstring()
336 LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) { in luaL_checknumber() argument
338 lua_Number d = lua_tonumberx(L, narg, &isnum); in luaL_checknumber()
340 tag_error(L, narg, LUA_TNUMBER); in luaL_checknumber()
345 LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) { in luaL_optnumber() argument
346 return luaL_opt(L, luaL_checknumber, narg, def); in luaL_optnumber()
350 LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) { in luaL_checkinteger() argument
352 lua_Integer d = lua_tointegerx(L, narg, &isnum); in luaL_checkinteger()
354 tag_error(L, narg, LUA_TNUMBER); in luaL_checkinteger()
359 LUALIB_API lua_Unsigned luaL_checkunsigned (lua_State *L, int narg) { in luaL_checkunsigned() argument
361 lua_Unsigned d = lua_tounsignedx(L, narg, &isnum); in luaL_checkunsigned()
363 tag_error(L, narg, LUA_TNUMBER); in luaL_checkunsigned()
368 LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg, in luaL_optinteger() argument
370 return luaL_opt(L, luaL_checkinteger, narg, def); in luaL_optinteger()
374 LUALIB_API lua_Unsigned luaL_optunsigned (lua_State *L, int narg, in luaL_optunsigned() argument
376 return luaL_opt(L, luaL_checkunsigned, narg, def); in luaL_optunsigned()
399 lua_State *L = B->L; in luaL_prepbuffsize() local
406 luaL_error(L, "buffer too large"); in luaL_prepbuffsize()
408 newbuff = (char *)lua_newuserdata(L, newsize * sizeof(char)); in luaL_prepbuffsize()
412 lua_remove(L, -2); /* remove old buffer */ in luaL_prepbuffsize()
433 lua_State *L = B->L; in luaL_pushresult() local
434 lua_pushlstring(L, B->b, B->n); in luaL_pushresult()
436 lua_remove(L, -2); /* remove old buffer */ in luaL_pushresult()
447 lua_State *L = B->L; in luaL_addvalue() local
449 const char *s = lua_tolstring(L, -1, &l); in luaL_addvalue()
451 lua_insert(L, -2); /* put value below buffer */ in luaL_addvalue()
453 lua_remove(L, (buffonstack(B)) ? -2 : -1); /* remove value */ in luaL_addvalue()
457 LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) { in luaL_buffinit() argument
458 B->L = L; in luaL_buffinit()
465 LUALIB_API char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz) { in luaL_buffinitsize() argument
466 luaL_buffinit(L, B); in luaL_buffinitsize()
483 LUALIB_API int luaL_ref (lua_State *L, int t) { in luaL_ref() argument
485 if (lua_isnil(L, -1)) { in luaL_ref()
486 lua_pop(L, 1); /* remove from stack */ in luaL_ref()
489 t = lua_absindex(L, t); in luaL_ref()
490 lua_rawgeti(L, t, freelist); /* get first free element */ in luaL_ref()
491 ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */ in luaL_ref()
492 lua_pop(L, 1); /* remove it from stack */ in luaL_ref()
494 lua_rawgeti(L, t, ref); /* remove it from list */ in luaL_ref()
495 lua_rawseti(L, t, freelist); /* (t[freelist] = t[ref]) */ in luaL_ref()
498 ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */ in luaL_ref()
499 lua_rawseti(L, t, ref); in luaL_ref()
504 LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { in luaL_unref() argument
506 t = lua_absindex(L, t); in luaL_unref()
507 lua_rawgeti(L, t, freelist); in luaL_unref()
508 lua_rawseti(L, t, ref); /* t[ref] = t[freelist] */ in luaL_unref()
509 lua_pushinteger(L, ref); in luaL_unref()
510 lua_rawseti(L, t, freelist); /* t[freelist] = ref */ in luaL_unref()
529 static const char *getS (lua_State *L, void *ud, size_t *size) { in getS() argument
531 (void)L; /* not used */ in getS()
539 LUALIB_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t size, in luaL_loadbufferx() argument
544 return lua_load(L, getS, &ls, name, mode); in luaL_loadbufferx()
548 LUALIB_API int luaL_loadstring (lua_State *L, const char *s) { in luaL_loadstring() argument
549 return luaL_loadbuffer(L, s, strlen(s), s); in luaL_loadstring()
556 LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) { in luaL_getmetafield() argument
557 if (!lua_getmetatable(L, obj)) /* no metatable? */ in luaL_getmetafield()
559 lua_pushstring(L, event); in luaL_getmetafield()
560 lua_rawget(L, -2); in luaL_getmetafield()
561 if (lua_isnil(L, -1)) { in luaL_getmetafield()
562 lua_pop(L, 2); /* remove metatable and metafield */ in luaL_getmetafield()
566 lua_remove(L, -2); /* remove only metatable */ in luaL_getmetafield()
572 LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) { in luaL_callmeta() argument
573 obj = lua_absindex(L, obj); in luaL_callmeta()
574 if (!luaL_getmetafield(L, obj, event)) /* no metafield? */ in luaL_callmeta()
576 lua_pushvalue(L, obj); in luaL_callmeta()
577 lua_call(L, 1, 1); in luaL_callmeta()
582 LUALIB_API int luaL_len (lua_State *L, int idx) { in luaL_len() argument
585 lua_len(L, idx); in luaL_len()
586 l = (int)lua_tointegerx(L, -1, &isnum); in luaL_len()
588 luaL_error(L, "object length is not a number"); in luaL_len()
589 lua_pop(L, 1); /* remove object */ in luaL_len()
594 LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { in luaL_tolstring() argument
595 if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */ in luaL_tolstring()
596 switch (lua_type(L, idx)) { in luaL_tolstring()
599 lua_pushvalue(L, idx); in luaL_tolstring()
602 lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false")); in luaL_tolstring()
605 lua_pushliteral(L, "nil"); in luaL_tolstring()
608 lua_pushfstring(L, "%s: %p", luaL_typename(L, idx), in luaL_tolstring()
609 lua_topointer(L, idx)); in luaL_tolstring()
613 return lua_tolstring(L, -1, len); in luaL_tolstring()
624 static const char *luaL_findtable (lua_State *L, int idx, in luaL_findtable() argument
627 if (idx) lua_pushvalue(L, idx); in luaL_findtable()
631 lua_pushlstring(L, fname, e - fname); in luaL_findtable()
632 lua_rawget(L, -2); in luaL_findtable()
633 if (lua_isnil(L, -1)) { /* no such field? */ in luaL_findtable()
634 lua_pop(L, 1); /* remove this nil */ in luaL_findtable()
635 lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */ in luaL_findtable()
636 lua_pushlstring(L, fname, e - fname); in luaL_findtable()
637 lua_pushvalue(L, -2); in luaL_findtable()
638 lua_settable(L, -4); /* set new table into field */ in luaL_findtable()
640 else if (!lua_istable(L, -1)) { /* field has a non-table value? */ in luaL_findtable()
641 lua_pop(L, 2); /* remove table and value */ in luaL_findtable()
644 lua_remove(L, -2); /* remove previous table */ in luaL_findtable()
667 LUALIB_API void luaL_pushmodule (lua_State *L, const char *modname, in luaL_pushmodule() argument
669 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); /* get _LOADED table */ in luaL_pushmodule()
670 lua_getfield(L, -1, modname); /* get _LOADED[modname] */ in luaL_pushmodule()
671 if (!lua_istable(L, -1)) { /* not found? */ in luaL_pushmodule()
672 lua_pop(L, 1); /* remove previous result */ in luaL_pushmodule()
674 lua_pushglobaltable(L); in luaL_pushmodule()
675 if (luaL_findtable(L, 0, modname, sizehint) != NULL) in luaL_pushmodule()
676 luaL_error(L, "name conflict for module " LUA_QS, modname); in luaL_pushmodule()
677 lua_pushvalue(L, -1); in luaL_pushmodule()
678 lua_setfield(L, -3, modname); /* _LOADED[modname] = new table */ in luaL_pushmodule()
680 lua_remove(L, -2); /* remove _LOADED table */ in luaL_pushmodule()
684 LUALIB_API void luaL_openlib (lua_State *L, const char *libname, in luaL_openlib() argument
686 luaL_checkversion(L); in luaL_openlib()
688 luaL_pushmodule(L, libname, libsize(l)); /* get/create library table */ in luaL_openlib()
689 lua_insert(L, -(nup + 1)); /* move library table to below upvalues */ in luaL_openlib()
692 luaL_setfuncs(L, l, nup); in luaL_openlib()
694 lua_pop(L, nup); /* remove upvalues */ in luaL_openlib()
705 LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { in luaL_setfuncs() argument
706 luaL_checkversion(L); in luaL_setfuncs()
707 luaL_checkstack(L, nup, "too many upvalues"); in luaL_setfuncs()
711 lua_pushvalue(L, -nup); in luaL_setfuncs()
712 lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ in luaL_setfuncs()
713 lua_setfield(L, -(nup + 2), l->name); in luaL_setfuncs()
715 lua_pop(L, nup); /* remove upvalues */ in luaL_setfuncs()
723 LUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) { in luaL_getsubtable() argument
724 lua_getfield(L, idx, fname); in luaL_getsubtable()
725 if (lua_istable(L, -1)) return 1; /* table already there */ in luaL_getsubtable()
727 lua_pop(L, 1); /* remove previous result */ in luaL_getsubtable()
728 idx = lua_absindex(L, idx); in luaL_getsubtable()
729 lua_newtable(L); in luaL_getsubtable()
730 lua_pushvalue(L, -1); /* copy to be left at top */ in luaL_getsubtable()
731 lua_setfield(L, idx, fname); /* assign new table to field */ in luaL_getsubtable()
743 LUALIB_API void luaL_requiref (lua_State *L, const char *modname, in luaL_requiref() argument
745 lua_pushcfunction(L, openf); in luaL_requiref()
746 lua_pushstring(L, modname); /* argument to open function */ in luaL_requiref()
747 lua_call(L, 1, 1); /* open module */ in luaL_requiref()
748 luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED"); in luaL_requiref()
749 lua_pushvalue(L, -2); /* make copy of module (call result) */ in luaL_requiref()
750 lua_setfield(L, -2, modname); /* _LOADED[modname] = module */ in luaL_requiref()
751 lua_pop(L, 1); /* remove _LOADED table */ in luaL_requiref()
753 lua_pushvalue(L, -1); /* copy of 'mod' */ in luaL_requiref()
754 lua_setglobal(L, modname); /* _G[modname] = module */ in luaL_requiref()
759 LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, in luaL_gsub() argument
764 luaL_buffinit(L, &b); in luaL_gsub()
772 return lua_tostring(L, -1); in luaL_gsub()
776 LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver) { in luaL_checkversion_() argument
777 const lua_Number *v = lua_version(L); in luaL_checkversion_()
779 luaL_error(L, "multiple Lua VMs detected"); in luaL_checkversion_()
781 luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f", in luaL_checkversion_()
784 lua_pushnumber(L, -(lua_Number)0x1234); in luaL_checkversion_()
785 if (lua_tointeger(L, -1) != -0x1234 || in luaL_checkversion_()
786 lua_tounsigned(L, -1) != (lua_Unsigned)-0x1234) in luaL_checkversion_()
787 luaL_error(L, "bad conversion number->int;" in luaL_checkversion_()
789 lua_pop(L, 1); in luaL_checkversion_()