mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-04-22 06:43:27 +00:00
backport lua_len from 5.2
This commit is contained in:
parent
23afb8dcee
commit
f543ff65fc
19
src/lj_api.c
19
src/lj_api.c
@ -806,6 +806,25 @@ LUA_API void lua_concat(lua_State *L, int n)
|
||||
/* else n == 1: nothing to do. */
|
||||
}
|
||||
|
||||
LUA_API void lua_len (lua_State *L, int idx)
|
||||
{
|
||||
TValue *o = index2adr_stack(L, idx);
|
||||
if (tvisstr(o)) {
|
||||
setnumV(L->top, strV(o)->len);
|
||||
} else if (tvistab(o) && (!LJ_52 || tvisnil(lj_meta_lookup(L, o, MM_len)))) {
|
||||
setnumV(L->top, lj_tab_len(tabV(o)));
|
||||
} else {
|
||||
TValue *v;
|
||||
L->top = lj_meta_len(L, o);
|
||||
L->top += 2;
|
||||
lj_vm_call(L, L->top-2, 1+1);
|
||||
L->top -= 2+LJ_FR2;
|
||||
v = L->top+1+LJ_FR2;
|
||||
copyTV(L, L->top, v);
|
||||
}
|
||||
incr_top(L);
|
||||
}
|
||||
|
||||
/* -- Object getters ------------------------------------------------------ */
|
||||
|
||||
LUA_API void lua_gettable(lua_State *L, int idx)
|
||||
|
@ -353,6 +353,7 @@ LUA_API void lua_copy (lua_State *L, int fromidx, int toidx);
|
||||
LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *isnum);
|
||||
LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *isnum);
|
||||
LUA_API size_t lua_rawlen (lua_State *L, int idx);
|
||||
LUA_API void lua_len (lua_State *L, int idx);
|
||||
|
||||
/* From Lua 5.3. */
|
||||
LUA_API int lua_isyieldable (lua_State *L);
|
||||
|
Loading…
Reference in New Issue
Block a user