Lines Matching refs:L
52 static int findfield (lua_State *L, int objidx, int level) { in findfield() argument
53 if (level == 0 || !lua_istable(L, -1)) in findfield()
55 lua_pushnil(L); /* start 'next' loop */ in findfield()
56 while (lua_next(L, -2)) { /* for each pair in table */ in findfield()
57 if (lua_type(L, -2) == LUA_TSTRING) { /* ignore non-string keys */ in findfield()
58 if (lua_rawequal(L, objidx, -1)) { /* found object? */ in findfield()
59 lua_pop(L, 1); /* remove value (but keep name) */ in findfield()
62 else if (findfield(L, objidx, level - 1)) { /* try recursively */ in findfield()
64 lua_pushliteral(L, "."); /* place '.' between the two names */ in findfield()
65 lua_replace(L, -3); /* (in the slot occupied by table) */ in findfield()
66 lua_concat(L, 3); /* lib_name.field_name */ in findfield()
70 lua_pop(L, 1); /* remove value */ in findfield()
79 static int pushglobalfuncname (lua_State *L, lua_Debug *ar) { in pushglobalfuncname() argument
80 int top = lua_gettop(L); in pushglobalfuncname()
81 lua_getinfo(L, "f", ar); /* push function */ in pushglobalfuncname()
82 lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); in pushglobalfuncname()
83 if (findfield(L, top + 1, 2)) { in pushglobalfuncname()
84 const char *name = lua_tostring(L, -1); in pushglobalfuncname()
86 lua_pushstring(L, name + 3); /* push name without prefix */ in pushglobalfuncname()
87 lua_remove(L, -2); /* remove original name */ in pushglobalfuncname()
89 lua_copy(L, -1, top + 1); /* copy name to proper place */ in pushglobalfuncname()
90 lua_settop(L, top + 1); /* remove table "loaded" and name copy */ in pushglobalfuncname()
94 lua_settop(L, top); /* remove function and global table */ in pushglobalfuncname()
100 static void pushfuncname (lua_State *L, lua_Debug *ar) { in pushfuncname() argument
101 if (pushglobalfuncname(L, ar)) { /* try first a global name */ in pushfuncname()
102 lua_pushfstring(L, "function '%s'", lua_tostring(L, -1)); in pushfuncname()
103 lua_remove(L, -2); /* remove name */ in pushfuncname()
106 lua_pushfstring(L, "%s '%s'", ar->namewhat, ar->name); /* use it */ in pushfuncname()
108 lua_pushliteral(L, "main chunk"); in pushfuncname()
110 lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined); in pushfuncname()
112 lua_pushliteral(L, "?"); in pushfuncname()
116 static int lastlevel (lua_State *L) { in lastlevel() argument
120 while (lua_getstack(L, le, &ar)) { li = le; le *= 2; } in lastlevel()
124 if (lua_getstack(L, m, &ar)) li = m + 1; in lastlevel()
131 LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, in luaL_traceback() argument
137 luaL_buffinit(L, &b); in luaL_traceback()
146 lua_pushfstring(L, "\n\t...\t(skipping %d levels)", n); in luaL_traceback()
153 lua_pushfstring(L, "\n\t%s: in ", ar.short_src); in luaL_traceback()
155 lua_pushfstring(L, "\n\t%s:%d: in ", ar.short_src, ar.currentline); in luaL_traceback()
157 pushfuncname(L, &ar); in luaL_traceback()
175 LUALIB_API int luaL_argerror (lua_State *L, int arg, const char *extramsg) { in luaL_argerror() argument
177 if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ in luaL_argerror()
178 return luaL_error(L, "bad argument #%d (%s)", arg, extramsg); in luaL_argerror()
179 lua_getinfo(L, "n", &ar); in luaL_argerror()
183 return luaL_error(L, "calling '%s' on bad self (%s)", in luaL_argerror()
187 ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?"; in luaL_argerror()
188 return luaL_error(L, "bad argument #%d to '%s' (%s)", in luaL_argerror()
193 int luaL_typeerror (lua_State *L, int arg, const char *tname) { in luaL_typeerror() argument
196 if (luaL_getmetafield(L, arg, "__name") == LUA_TSTRING) in luaL_typeerror()
197 typearg = lua_tostring(L, -1); /* use the given type name */ in luaL_typeerror()
198 else if (lua_type(L, arg) == LUA_TLIGHTUSERDATA) in luaL_typeerror()
201 typearg = luaL_typename(L, arg); /* standard name */ in luaL_typeerror()
202 msg = lua_pushfstring(L, "%s expected, got %s", tname, typearg); in luaL_typeerror()
203 return luaL_argerror(L, arg, msg); in luaL_typeerror()
207 static void tag_error (lua_State *L, int arg, int tag) { in tag_error() argument
208 luaL_typeerror(L, arg, lua_typename(L, tag)); in tag_error()
216 LUALIB_API void luaL_where (lua_State *L, int level) { in luaL_where() argument
218 if (lua_getstack(L, level, &ar)) { /* check function at level */ in luaL_where()
219 lua_getinfo(L, "Sl", &ar); /* get info about it */ in luaL_where()
221 lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline); in luaL_where()
225 lua_pushfstring(L, ""); /* else, no information available... */ in luaL_where()
234 LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { in luaL_error() argument
237 luaL_where(L, 1); in luaL_error()
238 lua_pushvfstring(L, fmt, argp); in luaL_error()
240 lua_concat(L, 2); in luaL_error()
241 return lua_error(L); in luaL_error()
245 LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) { in luaL_fileresult() argument
248 lua_pushboolean(L, 1); in luaL_fileresult()
252 luaL_pushfail(L); in luaL_fileresult()
254 lua_pushfstring(L, "%s: %s", fname, strerror(en)); in luaL_fileresult()
256 lua_pushstring(L, strerror(en)); in luaL_fileresult()
257 lua_pushinteger(L, en); in luaL_fileresult()
285 LUALIB_API int luaL_execresult (lua_State *L, int stat) { in luaL_execresult() argument
287 return luaL_fileresult(L, 0, NULL); in luaL_execresult()
292 lua_pushboolean(L, 1); in luaL_execresult()
294 luaL_pushfail(L); in luaL_execresult()
295 lua_pushstring(L, what); in luaL_execresult()
296 lua_pushinteger(L, stat); in luaL_execresult()
311 LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { in luaL_newmetatable() argument
312 if (luaL_getmetatable(L, tname) != LUA_TNIL) /* name already in use? */ in luaL_newmetatable()
314 lua_pop(L, 1); in luaL_newmetatable()
315 lua_createtable(L, 0, 2); /* create metatable */ in luaL_newmetatable()
316 lua_pushstring(L, tname); in luaL_newmetatable()
317 lua_setfield(L, -2, "__name"); /* metatable.__name = tname */ in luaL_newmetatable()
318 lua_pushvalue(L, -1); in luaL_newmetatable()
319 lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */ in luaL_newmetatable()
324 LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) { in luaL_setmetatable() argument
325 luaL_getmetatable(L, tname); in luaL_setmetatable()
326 lua_setmetatable(L, -2); in luaL_setmetatable()
330 LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { in luaL_testudata() argument
331 void *p = lua_touserdata(L, ud); in luaL_testudata()
333 if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ in luaL_testudata()
334 luaL_getmetatable(L, tname); /* get correct metatable */ in luaL_testudata()
335 if (!lua_rawequal(L, -1, -2)) /* not the same? */ in luaL_testudata()
337 lua_pop(L, 2); /* remove both metatables */ in luaL_testudata()
345 LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { in luaL_checkudata() argument
346 void *p = luaL_testudata(L, ud, tname); in luaL_checkudata()
347 luaL_argexpected(L, p != NULL, ud, tname); in luaL_checkudata()
360 LUALIB_API int luaL_checkoption (lua_State *L, int arg, const char *def, in luaL_checkoption() argument
362 const char *name = (def) ? luaL_optstring(L, arg, def) : in luaL_checkoption()
363 luaL_checkstring(L, arg); in luaL_checkoption()
368 return luaL_argerror(L, arg, in luaL_checkoption()
369 lua_pushfstring(L, "invalid option '%s'", name)); in luaL_checkoption()
380 LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg) { in luaL_checkstack() argument
381 if (!lua_checkstack(L, space)) { in luaL_checkstack()
383 luaL_error(L, "stack overflow (%s)", msg); in luaL_checkstack()
385 luaL_error(L, "stack overflow"); in luaL_checkstack()
390 LUALIB_API void luaL_checktype (lua_State *L, int arg, int t) { in luaL_checktype() argument
391 if (lua_type(L, arg) != t) in luaL_checktype()
392 tag_error(L, arg, t); in luaL_checktype()
396 LUALIB_API void luaL_checkany (lua_State *L, int arg) { in luaL_checkany() argument
397 if (lua_type(L, arg) == LUA_TNONE) in luaL_checkany()
398 luaL_argerror(L, arg, "value expected"); in luaL_checkany()
402 LUALIB_API const char *luaL_checklstring (lua_State *L, int arg, size_t *len) { in luaL_checklstring() argument
403 const char *s = lua_tolstring(L, arg, len); in luaL_checklstring()
404 if (!s) tag_error(L, arg, LUA_TSTRING); in luaL_checklstring()
409 LUALIB_API const char *luaL_optlstring (lua_State *L, int arg, in luaL_optlstring() argument
411 if (lua_isnoneornil(L, arg)) { in luaL_optlstring()
416 else return luaL_checklstring(L, arg, len); in luaL_optlstring()
420 LUALIB_API lua_Number luaL_checknumber (lua_State *L, int arg) { in luaL_checknumber() argument
422 lua_Number d = lua_tonumberx(L, arg, &isnum); in luaL_checknumber()
424 tag_error(L, arg, LUA_TNUMBER); in luaL_checknumber()
429 LUALIB_API lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number def) { in luaL_optnumber() argument
430 return luaL_opt(L, luaL_checknumber, arg, def); in luaL_optnumber()
434 static void interror (lua_State *L, int arg) { in interror() argument
435 if (lua_isnumber(L, arg)) in interror()
436 luaL_argerror(L, arg, "number has no integer representation"); in interror()
438 tag_error(L, arg, LUA_TNUMBER); in interror()
442 LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int arg) { in luaL_checkinteger() argument
444 lua_Integer d = lua_tointegerx(L, arg, &isnum); in luaL_checkinteger()
446 interror(L, arg); in luaL_checkinteger()
452 LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int arg, in luaL_optinteger() argument
454 return luaL_opt(L, luaL_checkinteger, arg, def); in luaL_optinteger()
473 static void *resizebox (lua_State *L, int idx, size_t newsize) { in resizebox() argument
475 lua_Alloc allocf = lua_getallocf(L, &ud); in resizebox()
476 UBox *box = (UBox *)lua_touserdata(L, idx); in resizebox()
479 lua_pushliteral(L, "not enough memory"); in resizebox()
480 lua_error(L); /* raise a memory error */ in resizebox()
488 static int boxgc (lua_State *L) { in boxgc() argument
489 resizebox(L, 1, 0); in boxgc()
501 static void newbox (lua_State *L) { in newbox() argument
502 UBox *box = (UBox *)lua_newuserdatauv(L, sizeof(UBox), 0); in newbox()
505 if (luaL_newmetatable(L, "_UBOX*")) /* creating metatable? */ in newbox()
506 luaL_setfuncs(L, boxmt, 0); /* set its metamethods */ in newbox()
507 lua_setmetatable(L, -2); in newbox()
525 return luaL_error(B->L, "buffer too large"); in newbuffsize()
541 lua_State *L = B->L; in prepbuffsize() local
546 newbuff = (char *)resizebox(L, boxidx, newsize); /* resize it */ in prepbuffsize()
548 lua_pushnil(L); /* reserve slot for final result */ in prepbuffsize()
549 newbox(L); /* create a new box */ in prepbuffsize()
551 lua_rotate(L, boxidx - 1, 2); in prepbuffsize()
552 lua_toclose(L, boxidx); in prepbuffsize()
553 newbuff = (char *)resizebox(L, boxidx, newsize); in prepbuffsize()
585 lua_State *L = B->L; in luaL_pushresult() local
586 lua_pushlstring(L, B->b, B->n); in luaL_pushresult()
588 lua_copy(L, -1, -3); /* move string to reserved slot */ in luaL_pushresult()
589 lua_pop(L, 2); /* pop string and box (closing the box) */ in luaL_pushresult()
610 lua_State *L = B->L; in luaL_addvalue() local
612 const char *s = lua_tolstring(L, -1, &len); in luaL_addvalue()
616 lua_pop(L, 1); /* pop string */ in luaL_addvalue()
620 LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) { in luaL_buffinit() argument
621 B->L = L; in luaL_buffinit()
628 LUALIB_API char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz) { in luaL_buffinitsize() argument
629 luaL_buffinit(L, B); in luaL_buffinitsize()
646 LUALIB_API int luaL_ref (lua_State *L, int t) { in luaL_ref() argument
648 if (lua_isnil(L, -1)) { in luaL_ref()
649 lua_pop(L, 1); /* remove from stack */ in luaL_ref()
652 t = lua_absindex(L, t); in luaL_ref()
653 lua_rawgeti(L, t, freelist); /* get first free element */ in luaL_ref()
654 ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */ in luaL_ref()
655 lua_pop(L, 1); /* remove it from stack */ in luaL_ref()
657 lua_rawgeti(L, t, ref); /* remove it from list */ in luaL_ref()
658 lua_rawseti(L, t, freelist); /* (t[freelist] = t[ref]) */ in luaL_ref()
661 ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */ in luaL_ref()
662 lua_rawseti(L, t, ref); in luaL_ref()
667 LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { in luaL_unref() argument
669 t = lua_absindex(L, t); in luaL_unref()
670 lua_rawgeti(L, t, freelist); in luaL_unref()
671 lua_rawseti(L, t, ref); /* t[ref] = t[freelist] */ in luaL_unref()
672 lua_pushinteger(L, ref); in luaL_unref()
673 lua_rawseti(L, t, freelist); /* t[freelist] = ref */ in luaL_unref()
693 static const char *getF (lua_State *L, void *ud, size_t *size) { in getF() argument
695 (void)L; /* not used */ in getF()
711 static int errfile (lua_State *L, const char *what, int fnameindex) { in errfile() argument
713 const char *filename = lua_tostring(L, fnameindex) + 1; in errfile()
714 lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr); in errfile()
715 lua_remove(L, fnameindex); in errfile()
754 LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename, in luaL_loadfilex() argument
759 int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */ in luaL_loadfilex()
761 lua_pushliteral(L, "=stdin"); in luaL_loadfilex()
765 lua_pushfstring(L, "@%s", filename); in luaL_loadfilex()
767 if (lf.f == NULL) return errfile(L, "open", fnameindex); in luaL_loadfilex()
773 if (lf.f == NULL) return errfile(L, "reopen", fnameindex); in luaL_loadfilex()
778 status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode); in luaL_loadfilex()
782 lua_settop(L, fnameindex); /* ignore results from 'lua_load' */ in luaL_loadfilex()
783 return errfile(L, "read", fnameindex); in luaL_loadfilex()
785 lua_remove(L, fnameindex); in luaL_loadfilex()
796 static const char *getS (lua_State *L, void *ud, size_t *size) { in getS() argument
798 (void)L; /* not used */ in getS()
806 LUALIB_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t size, in luaL_loadbufferx() argument
811 return lua_load(L, getS, &ls, name, mode); in luaL_loadbufferx()
815 LUALIB_API int luaL_loadstring (lua_State *L, const char *s) { in luaL_loadstring() argument
816 return luaL_loadbuffer(L, s, strlen(s), s); in luaL_loadstring()
823 LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) { in luaL_getmetafield() argument
824 if (!lua_getmetatable(L, obj)) /* no metatable? */ in luaL_getmetafield()
828 lua_pushstring(L, event); in luaL_getmetafield()
829 tt = lua_rawget(L, -2); in luaL_getmetafield()
831 lua_pop(L, 2); /* remove metatable and metafield */ in luaL_getmetafield()
833 lua_remove(L, -2); /* remove only metatable */ in luaL_getmetafield()
839 LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) { in luaL_callmeta() argument
840 obj = lua_absindex(L, obj); in luaL_callmeta()
841 if (luaL_getmetafield(L, obj, event) == LUA_TNIL) /* no metafield? */ in luaL_callmeta()
843 lua_pushvalue(L, obj); in luaL_callmeta()
844 lua_call(L, 1, 1); in luaL_callmeta()
849 LUALIB_API lua_Integer luaL_len (lua_State *L, int idx) { in luaL_len() argument
852 lua_len(L, idx); in luaL_len()
853 l = lua_tointegerx(L, -1, &isnum); in luaL_len()
855 luaL_error(L, "object length is not an integer"); in luaL_len()
856 lua_pop(L, 1); /* remove object */ in luaL_len()
861 LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { in luaL_tolstring() argument
862 if (luaL_callmeta(L, idx, "__tostring")) { /* metafield? */ in luaL_tolstring()
863 if (!lua_isstring(L, -1)) in luaL_tolstring()
864 luaL_error(L, "'__tostring' must return a string"); in luaL_tolstring()
867 switch (lua_type(L, idx)) { in luaL_tolstring()
869 if (lua_isinteger(L, idx)) in luaL_tolstring()
870 lua_pushfstring(L, "%I", (LUAI_UACINT)lua_tointeger(L, idx)); in luaL_tolstring()
872 lua_pushfstring(L, "%f", (LUAI_UACNUMBER)lua_tonumber(L, idx)); in luaL_tolstring()
876 lua_pushvalue(L, idx); in luaL_tolstring()
879 lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false")); in luaL_tolstring()
882 lua_pushliteral(L, "nil"); in luaL_tolstring()
885 int tt = luaL_getmetafield(L, idx, "__name"); /* try name */ in luaL_tolstring()
886 const char *kind = (tt == LUA_TSTRING) ? lua_tostring(L, -1) : in luaL_tolstring()
887 luaL_typename(L, idx); in luaL_tolstring()
888 lua_pushfstring(L, "%s: %p", kind, lua_topointer(L, idx)); in luaL_tolstring()
890 lua_remove(L, -2); /* remove '__name' */ in luaL_tolstring()
895 return lua_tolstring(L, -1, len); in luaL_tolstring()
904 LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { in luaL_setfuncs() argument
905 luaL_checkstack(L, nup, "too many upvalues"); in luaL_setfuncs()
908 lua_pushboolean(L, 0); in luaL_setfuncs()
912 lua_pushvalue(L, -nup); in luaL_setfuncs()
913 lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ in luaL_setfuncs()
915 lua_setfield(L, -(nup + 2), l->name); in luaL_setfuncs()
917 lua_pop(L, nup); /* remove upvalues */ in luaL_setfuncs()
925 LUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) { in luaL_getsubtable() argument
926 if (lua_getfield(L, idx, fname) == LUA_TTABLE) in luaL_getsubtable()
929 lua_pop(L, 1); /* remove previous result */ in luaL_getsubtable()
930 idx = lua_absindex(L, idx); in luaL_getsubtable()
931 lua_newtable(L); in luaL_getsubtable()
932 lua_pushvalue(L, -1); /* copy to be left at top */ in luaL_getsubtable()
933 lua_setfield(L, idx, fname); /* assign new table to field */ in luaL_getsubtable()
945 LUALIB_API void luaL_requiref (lua_State *L, const char *modname, in luaL_requiref() argument
947 luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); in luaL_requiref()
948 lua_getfield(L, -1, modname); /* LOADED[modname] */ in luaL_requiref()
949 if (!lua_toboolean(L, -1)) { /* package not already loaded? */ in luaL_requiref()
950 lua_pop(L, 1); /* remove field */ in luaL_requiref()
951 lua_pushcfunction(L, openf); in luaL_requiref()
952 lua_pushstring(L, modname); /* argument to open function */ in luaL_requiref()
953 lua_call(L, 1, 1); /* call 'openf' to open module */ in luaL_requiref()
954 lua_pushvalue(L, -1); /* make copy of module (call result) */ in luaL_requiref()
955 lua_setfield(L, -3, modname); /* LOADED[modname] = module */ in luaL_requiref()
957 lua_remove(L, -2); /* remove LOADED table */ in luaL_requiref()
959 lua_pushvalue(L, -1); /* copy of module */ in luaL_requiref()
960 lua_setglobal(L, modname); /* _G[modname] = module */ in luaL_requiref()
978 LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, in luaL_gsub() argument
981 luaL_buffinit(L, &b); in luaL_gsub()
984 return lua_tostring(L, -1); in luaL_gsub()
999 static int panic (lua_State *L) { in panic() argument
1000 const char *msg = lua_tostring(L, -1); in panic()
1023 static int checkcontrol (lua_State *L, const char *message, int tocont) { in checkcontrol() argument
1028 lua_setwarnf(L, warnfoff, L); /* turn warnings off */ in checkcontrol()
1030 lua_setwarnf(L, warnfon, L); /* turn warnings on */ in checkcontrol()
1046 lua_State *L = (lua_State *)ud; in warnfcont() local
1049 lua_setwarnf(L, warnfcont, L); /* to be continued */ in warnfcont()
1052 lua_setwarnf(L, warnfon, L); /* next call is a new message */ in warnfcont()
1066 lua_State *L = lua_newstate(l_alloc, NULL); in luaL_newstate() local
1067 if (L) { in luaL_newstate()
1068 lua_atpanic(L, &panic); in luaL_newstate()
1069 lua_setwarnf(L, warnfoff, L); /* default is warnings off */ in luaL_newstate()
1071 return L; in luaL_newstate()
1075 LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz) { in luaL_checkversion_() argument
1076 lua_Number v = lua_version(L); in luaL_checkversion_()
1078 luaL_error(L, "core and library have incompatible numeric types"); in luaL_checkversion_()
1080 luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f", in luaL_checkversion_()