Lines Matching +full:1 +full:l
34 ** search for 'objidx' in table at index -1.
35 ** return 1 + string at top if find a good name.
37 static int findfield (lua_State *L, int objidx, int level) { in findfield() argument
38 if (level == 0 || !lua_istable(L, -1)) in findfield()
40 lua_pushnil(L); /* start 'next' loop */ in findfield()
41 while (lua_next(L, -2)) { /* for each pair in table */ in findfield()
42 if (lua_type(L, -2) == LUA_TSTRING) { /* ignore non-string keys */ in findfield()
43 if (lua_rawequal(L, objidx, -1)) { /* found object? */ in findfield()
44 lua_pop(L, 1); /* remove value (but keep name) */ in findfield()
45 return 1; in findfield()
47 else if (findfield(L, objidx, level - 1)) { /* try recursively */ in findfield()
48 lua_remove(L, -2); /* remove table (but keep name) */ in findfield()
49 lua_pushliteral(L, "."); in findfield()
50 lua_insert(L, -2); /* place '.' between the two names */ in findfield()
51 lua_concat(L, 3); in findfield()
52 return 1; in findfield()
55 lua_pop(L, 1); /* remove value */ in findfield()
61 static int pushglobalfuncname (lua_State *L, lua_Debug *ar) { in pushglobalfuncname() argument
62 int top = lua_gettop(L); in pushglobalfuncname()
63 lua_getinfo(L, "f", ar); /* push function */ in pushglobalfuncname()
64 lua_pushglobaltable(L); in pushglobalfuncname()
65 if (findfield(L, top + 1, 2)) { in pushglobalfuncname()
66 lua_copy(L, -1, top + 1); /* move name to proper place */ in pushglobalfuncname()
67 lua_pop(L, 2); /* remove pushed values */ in pushglobalfuncname()
68 return 1; in pushglobalfuncname()
71 lua_settop(L, top); /* remove function and global table */ in pushglobalfuncname()
77 static void pushfuncname (lua_State *L, lua_Debug *ar) { in pushfuncname() argument
79 lua_pushfstring(L, "function " LUA_QS, ar->name); in pushfuncname()
81 lua_pushliteral(L, "main chunk"); in pushfuncname()
83 if (pushglobalfuncname(L, ar)) { in pushfuncname()
84 lua_pushfstring(L, "function " LUA_QS, lua_tostring(L, -1)); in pushfuncname()
85 lua_remove(L, -2); /* remove name */ in pushfuncname()
88 lua_pushliteral(L, "?"); in pushfuncname()
91 lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined); in pushfuncname()
95 static int countlevels (lua_State *L) { in countlevels() argument
97 int li = 1, le = 1; in countlevels()
99 while (lua_getstack(L, le, &ar)) { li = le; le *= 2; } in countlevels()
103 if (lua_getstack(L, m, &ar)) li = m + 1; in countlevels()
106 return le - 1; in countlevels()
110 LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, in luaL_traceback() argument
113 int top = lua_gettop(L); in luaL_traceback()
116 if (msg) lua_pushfstring(L, "%s\n", msg); in luaL_traceback()
117 lua_pushliteral(L, "stack traceback:"); in luaL_traceback()
120 lua_pushliteral(L, "\n\t..."); /* add a '...' */ in luaL_traceback()
125 lua_pushfstring(L, "\n\t%s:", ar.short_src); in luaL_traceback()
127 lua_pushfstring(L, "%d:", ar.currentline); in luaL_traceback()
128 lua_pushliteral(L, " in "); in luaL_traceback()
129 pushfuncname(L, &ar); in luaL_traceback()
131 lua_pushliteral(L, "\n\t(...tail calls...)"); in luaL_traceback()
132 lua_concat(L, lua_gettop(L) - top); in luaL_traceback()
135 lua_concat(L, lua_gettop(L) - top); in luaL_traceback()
147 LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { in luaL_argerror() argument
149 if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ in luaL_argerror()
150 return luaL_error(L, "bad argument #%d (%s)", narg, extramsg); in luaL_argerror()
151 lua_getinfo(L, "n", &ar); in luaL_argerror()
155 return luaL_error(L, "calling " LUA_QS " on bad self (%s)", in luaL_argerror()
159 ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?"; in luaL_argerror()
160 return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)", in luaL_argerror()
165 static int typeerror (lua_State *L, int narg, const char *tname) { in typeerror() argument
166 const char *msg = lua_pushfstring(L, "%s expected, got %s", in typeerror()
167 tname, luaL_typename(L, narg)); in typeerror()
168 return luaL_argerror(L, narg, msg); in typeerror()
172 static void tag_error (lua_State *L, int narg, int tag) { in tag_error() argument
173 typeerror(L, narg, lua_typename(L, tag)); in tag_error()
177 LUALIB_API void luaL_where (lua_State *L, int level) { in luaL_where() argument
179 if (lua_getstack(L, level, &ar)) { /* check function at level */ in luaL_where()
180 lua_getinfo(L, "Sl", &ar); /* get info about it */ in luaL_where()
182 lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline); in luaL_where()
186 lua_pushliteral(L, ""); /* else, no information available... */ in luaL_where()
190 LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { in luaL_error() argument
193 luaL_where(L, 1); in luaL_error()
194 lua_pushvfstring(L, fmt, argp); in luaL_error()
196 lua_concat(L, 2); in luaL_error()
197 return lua_error(L); in luaL_error()
232 LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { in luaL_newmetatable() argument
233 luaL_getmetatable(L, tname); /* try to get metatable */ in luaL_newmetatable()
234 if (!lua_isnil(L, -1)) /* name already in use? */ in luaL_newmetatable()
236 lua_pop(L, 1); in luaL_newmetatable()
237 lua_newtable(L); /* create metatable */ in luaL_newmetatable()
238 lua_pushvalue(L, -1); in luaL_newmetatable()
239 lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */ in luaL_newmetatable()
240 return 1; in luaL_newmetatable()
244 LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) { in luaL_setmetatable() argument
245 luaL_getmetatable(L, tname); in luaL_setmetatable()
246 lua_setmetatable(L, -2); in luaL_setmetatable()
250 LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { in luaL_testudata() argument
251 void *p = lua_touserdata(L, ud); in luaL_testudata()
253 if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ in luaL_testudata()
254 luaL_getmetatable(L, tname); /* get correct metatable */ in luaL_testudata()
255 if (!lua_rawequal(L, -1, -2)) /* not the same? */ in luaL_testudata()
257 lua_pop(L, 2); /* remove both metatables */ in luaL_testudata()
265 LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { in luaL_checkudata() argument
266 void *p = luaL_testudata(L, ud, tname); in luaL_checkudata()
267 if (p == NULL) typeerror(L, ud, tname); in luaL_checkudata()
280 LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, in luaL_checkoption() argument
282 const char *name = (def) ? luaL_optstring(L, narg, def) : in luaL_checkoption()
283 luaL_checkstring(L, narg); in luaL_checkoption()
288 return luaL_argerror(L, narg, in luaL_checkoption()
289 lua_pushfstring(L, "invalid option " LUA_QS, name)); in luaL_checkoption()
293 LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg) { in luaL_checkstack() argument
296 if (!lua_checkstack(L, space + extra)) { in luaL_checkstack()
298 luaL_error(L, "stack overflow (%s)", msg); in luaL_checkstack()
300 luaL_error(L, "stack overflow"); in luaL_checkstack()
305 LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) { in luaL_checktype() argument
306 if (lua_type(L, narg) != t) in luaL_checktype()
307 tag_error(L, narg, t); in luaL_checktype()
311 LUALIB_API void luaL_checkany (lua_State *L, int narg) { in luaL_checkany() argument
312 if (lua_type(L, narg) == LUA_TNONE) in luaL_checkany()
313 luaL_argerror(L, narg, "value expected"); in luaL_checkany()
317 LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { in luaL_checklstring() argument
318 const char *s = lua_tolstring(L, narg, len); in luaL_checklstring()
319 if (!s) tag_error(L, narg, LUA_TSTRING); in luaL_checklstring()
324 LUALIB_API const char *luaL_optlstring (lua_State *L, int narg, in luaL_optlstring() argument
326 if (lua_isnoneornil(L, narg)) { in luaL_optlstring()
331 else return luaL_checklstring(L, narg, len); in luaL_optlstring()
335 LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) { in luaL_checknumber() argument
337 lua_Number d = lua_tonumberx(L, narg, &isnum); in luaL_checknumber()
339 tag_error(L, narg, LUA_TNUMBER); in luaL_checknumber()
344 LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) { in luaL_optnumber() argument
345 return luaL_opt(L, luaL_checknumber, narg, def); in luaL_optnumber()
349 LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) { in luaL_checkinteger() argument
351 lua_Integer d = lua_tointegerx(L, narg, &isnum); in luaL_checkinteger()
353 tag_error(L, narg, LUA_TNUMBER); in luaL_checkinteger()
358 LUALIB_API lua_Unsigned luaL_checkunsigned (lua_State *L, int narg) { in luaL_checkunsigned() argument
360 lua_Unsigned d = lua_tounsignedx(L, narg, &isnum); in luaL_checkunsigned()
362 tag_error(L, narg, LUA_TNUMBER); in luaL_checkunsigned()
367 LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg, in luaL_optinteger() argument
369 return luaL_opt(L, luaL_checkinteger, narg, def); in luaL_optinteger()
373 LUALIB_API lua_Unsigned luaL_optunsigned (lua_State *L, int narg, in luaL_optunsigned() argument
375 return luaL_opt(L, luaL_checkunsigned, narg, def); in luaL_optunsigned()
398 lua_State *L = B->L; in luaL_prepbuffsize() local
405 luaL_error(L, "buffer too large"); in luaL_prepbuffsize()
407 newbuff = (char *)lua_newuserdata(L, newsize * sizeof(char)); in luaL_prepbuffsize()
411 lua_remove(L, -2); /* remove old buffer */ in luaL_prepbuffsize()
419 LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { in luaL_addlstring() argument
420 char *b = luaL_prepbuffsize(B, l); in luaL_addlstring()
421 memcpy(b, s, l * sizeof(char)); in luaL_addlstring()
422 luaL_addsize(B, l); in luaL_addlstring()
432 lua_State *L = B->L; in luaL_pushresult() local
433 lua_pushlstring(L, B->b, B->n); in luaL_pushresult()
435 lua_remove(L, -2); /* remove old buffer */ in luaL_pushresult()
446 lua_State *L = B->L; in luaL_addvalue() local
447 size_t l; in luaL_addvalue() local
448 const char *s = lua_tolstring(L, -1, &l); in luaL_addvalue()
450 lua_insert(L, -2); /* put value below buffer */ in luaL_addvalue()
451 luaL_addlstring(B, s, l); in luaL_addvalue()
452 lua_remove(L, (buffonstack(B)) ? -2 : -1); /* remove value */ in luaL_addvalue()
456 LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) { in luaL_buffinit() argument
457 B->L = L; in luaL_buffinit()
464 LUALIB_API char *luaL_buffinitsize (lua_State *L, luaL_Buffer *B, size_t sz) { in luaL_buffinitsize() argument
465 luaL_buffinit(L, B); in luaL_buffinitsize()
482 LUALIB_API int luaL_ref (lua_State *L, int t) { in luaL_ref() argument
484 if (lua_isnil(L, -1)) { in luaL_ref()
485 lua_pop(L, 1); /* remove from stack */ in luaL_ref()
488 t = lua_absindex(L, t); in luaL_ref()
489 lua_rawgeti(L, t, freelist); /* get first free element */ in luaL_ref()
490 ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */ in luaL_ref()
491 lua_pop(L, 1); /* remove it from stack */ in luaL_ref()
493 lua_rawgeti(L, t, ref); /* remove it from list */ in luaL_ref()
494 lua_rawseti(L, t, freelist); /* (t[freelist] = t[ref]) */ in luaL_ref()
497 ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */ in luaL_ref()
498 lua_rawseti(L, t, ref); in luaL_ref()
503 LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { in luaL_unref() argument
505 t = lua_absindex(L, t); in luaL_unref()
506 lua_rawgeti(L, t, freelist); in luaL_unref()
507 lua_rawseti(L, t, ref); /* t[ref] = t[freelist] */ in luaL_unref()
508 lua_pushinteger(L, ref); in luaL_unref()
509 lua_rawseti(L, t, freelist); /* t[freelist] = ref */ in luaL_unref()
528 static const char *getS (lua_State *L, void *ud, size_t *size) { in getS() argument
530 (void)L; /* not used */ in getS()
538 LUALIB_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t size, in luaL_loadbufferx() argument
543 return lua_load(L, getS, &ls, name, mode); in luaL_loadbufferx()
547 LUALIB_API int luaL_loadstring (lua_State *L, const char *s) { in luaL_loadstring() argument
548 return luaL_loadbuffer(L, s, strlen(s), s); in luaL_loadstring()
555 LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) { in luaL_getmetafield() argument
556 if (!lua_getmetatable(L, obj)) /* no metatable? */ in luaL_getmetafield()
558 lua_pushstring(L, event); in luaL_getmetafield()
559 lua_rawget(L, -2); in luaL_getmetafield()
560 if (lua_isnil(L, -1)) { in luaL_getmetafield()
561 lua_pop(L, 2); /* remove metatable and metafield */ in luaL_getmetafield()
565 lua_remove(L, -2); /* remove only metatable */ in luaL_getmetafield()
566 return 1; in luaL_getmetafield()
571 LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) { in luaL_callmeta() argument
572 obj = lua_absindex(L, obj); in luaL_callmeta()
573 if (!luaL_getmetafield(L, obj, event)) /* no metafield? */ in luaL_callmeta()
575 lua_pushvalue(L, obj); in luaL_callmeta()
576 lua_call(L, 1, 1); in luaL_callmeta()
577 return 1; in luaL_callmeta()
581 LUALIB_API int luaL_len (lua_State *L, int idx) { in luaL_len() argument
582 int l; in luaL_len() local
584 lua_len(L, idx); in luaL_len()
585 l = (int)lua_tointegerx(L, -1, &isnum); in luaL_len()
587 luaL_error(L, "object length is not a number"); in luaL_len()
588 lua_pop(L, 1); /* remove object */ in luaL_len()
589 return l; in luaL_len()
593 LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { in luaL_tolstring() argument
594 if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */ in luaL_tolstring()
595 switch (lua_type(L, idx)) { in luaL_tolstring()
598 lua_pushvalue(L, idx); in luaL_tolstring()
601 lua_pushstring(L, (lua_toboolean(L, idx) ? "true" : "false")); in luaL_tolstring()
604 lua_pushliteral(L, "nil"); in luaL_tolstring()
607 lua_pushfstring(L, "%s: %p", luaL_typename(L, idx), in luaL_tolstring()
608 lua_topointer(L, idx)); in luaL_tolstring()
612 return lua_tolstring(L, -1, len); in luaL_tolstring()
623 static const char *luaL_findtable (lua_State *L, int idx, in luaL_findtable() argument
626 if (idx) lua_pushvalue(L, idx); in luaL_findtable()
630 lua_pushlstring(L, fname, e - fname); in luaL_findtable()
631 lua_rawget(L, -2); in luaL_findtable()
632 if (lua_isnil(L, -1)) { /* no such field? */ in luaL_findtable()
633 lua_pop(L, 1); /* remove this nil */ in luaL_findtable()
634 lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */ in luaL_findtable()
635 lua_pushlstring(L, fname, e - fname); in luaL_findtable()
636 lua_pushvalue(L, -2); in luaL_findtable()
637 lua_settable(L, -4); /* set new table into field */ in luaL_findtable()
639 else if (!lua_istable(L, -1)) { /* field has a non-table value? */ in luaL_findtable()
640 lua_pop(L, 2); /* remove table and value */ in luaL_findtable()
643 lua_remove(L, -2); /* remove previous table */ in luaL_findtable()
644 fname = e + 1; in luaL_findtable()
653 static int libsize (const luaL_Reg *l) { in libsize() argument
655 for (; l && l->name; l++) size++; in libsize()
666 LUALIB_API void luaL_pushmodule (lua_State *L, const char *modname, in luaL_pushmodule() argument
668 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 1); /* get _LOADED table */ in luaL_pushmodule()
669 lua_getfield(L, -1, modname); /* get _LOADED[modname] */ in luaL_pushmodule()
670 if (!lua_istable(L, -1)) { /* not found? */ in luaL_pushmodule()
671 lua_pop(L, 1); /* remove previous result */ in luaL_pushmodule()
673 lua_pushglobaltable(L); in luaL_pushmodule()
674 if (luaL_findtable(L, 0, modname, sizehint) != NULL) in luaL_pushmodule()
675 luaL_error(L, "name conflict for module " LUA_QS, modname); in luaL_pushmodule()
676 lua_pushvalue(L, -1); in luaL_pushmodule()
677 lua_setfield(L, -3, modname); /* _LOADED[modname] = new table */ in luaL_pushmodule()
679 lua_remove(L, -2); /* remove _LOADED table */ in luaL_pushmodule()
683 LUALIB_API void luaL_openlib (lua_State *L, const char *libname, in luaL_openlib() argument
684 const luaL_Reg *l, int nup) { in luaL_openlib() argument
685 luaL_checkversion(L); in luaL_openlib()
687 luaL_pushmodule(L, libname, libsize(l)); /* get/create library table */ in luaL_openlib()
688 lua_insert(L, -(nup + 1)); /* move library table to below upvalues */ in luaL_openlib()
690 if (l) in luaL_openlib()
691 luaL_setfuncs(L, l, nup); in luaL_openlib()
693 lua_pop(L, nup); /* remove upvalues */ in luaL_openlib()
700 ** set functions from list 'l' into table at top - 'nup'; each
704 LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { in luaL_setfuncs() argument
705 luaL_checkversion(L); in luaL_setfuncs()
706 luaL_checkstack(L, nup, "too many upvalues"); in luaL_setfuncs()
707 for (; l->name != NULL; l++) { /* fill the table with given functions */ in luaL_setfuncs()
710 lua_pushvalue(L, -nup); in luaL_setfuncs()
711 lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ in luaL_setfuncs()
712 lua_setfield(L, -(nup + 2), l->name); in luaL_setfuncs()
714 lua_pop(L, nup); /* remove upvalues */ in luaL_setfuncs()
722 LUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) { in luaL_getsubtable() argument
723 lua_getfield(L, idx, fname); in luaL_getsubtable()
724 if (lua_istable(L, -1)) return 1; /* table already there */ in luaL_getsubtable()
726 lua_pop(L, 1); /* remove previous result */ in luaL_getsubtable()
727 idx = lua_absindex(L, idx); in luaL_getsubtable()
728 lua_newtable(L); in luaL_getsubtable()
729 lua_pushvalue(L, -1); /* copy to be left at top */ in luaL_getsubtable()
730 lua_setfield(L, idx, fname); /* assign new table to field */ in luaL_getsubtable()
742 LUALIB_API void luaL_requiref (lua_State *L, const char *modname, in luaL_requiref() argument
744 lua_pushcfunction(L, openf); in luaL_requiref()
745 lua_pushstring(L, modname); /* argument to open function */ in luaL_requiref()
746 lua_call(L, 1, 1); /* open module */ in luaL_requiref()
747 luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED"); in luaL_requiref()
748 lua_pushvalue(L, -2); /* make copy of module (call result) */ in luaL_requiref()
749 lua_setfield(L, -2, modname); /* _LOADED[modname] = module */ in luaL_requiref()
750 lua_pop(L, 1); /* remove _LOADED table */ in luaL_requiref()
752 lua_pushvalue(L, -1); /* copy of 'mod' */ in luaL_requiref()
753 lua_setglobal(L, modname); /* _G[modname] = module */ in luaL_requiref()
758 LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, in luaL_gsub() argument
761 size_t l = strlen(p); in luaL_gsub() local
763 luaL_buffinit(L, &b); in luaL_gsub()
767 s = wild + l; /* continue after `p' */ in luaL_gsub()
771 return lua_tostring(L, -1); in luaL_gsub()
775 LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver) { in luaL_checkversion_() argument
776 const lua_Number *v = lua_version(L); in luaL_checkversion_()
778 luaL_error(L, "multiple Lua VMs detected"); in luaL_checkversion_()
780 luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f", in luaL_checkversion_()
783 lua_pushnumber(L, -(lua_Number)0x1234); in luaL_checkversion_()
784 if (lua_tointeger(L, -1) != -0x1234 || in luaL_checkversion_()
785 lua_tounsigned(L, -1) != (lua_Unsigned)-0x1234) in luaL_checkversion_()
786 luaL_error(L, "bad conversion number->int;" in luaL_checkversion_()
788 lua_pop(L, 1); in luaL_checkversion_()