From c3a6f3fa1c6360d4ea2e32f9415f51e8e55093b4 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 17 Dec 2009 14:20:01 -0200 Subject: 'lua_objlen' replaced by 'lua_rawlen', 'lua_len', and 'luaL_len' --- lapi.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'lapi.c') diff --git a/lapi.c b/lapi.c index b26efbc0..3b24d70c 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.103 2009/12/08 16:15:43 roberto Exp roberto $ +** $Id: lapi.c,v 2.104 2009/12/15 11:25:36 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -374,20 +374,13 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { } -LUA_API size_t lua_objlen (lua_State *L, int idx) { +LUA_API size_t lua_rawlen (lua_State *L, int idx) { StkId o = index2addr(L, idx); - if (ttisuserdata(o)) return uvalue(o)->len; - else { - size_t res; - TValue temp; - lua_lock(L); - res = luaV_len(L, o, &temp); - if (res == cast(size_t, -1)) { - const TValue *t = &temp; - res = tonumber(t, &temp) ? nvalue(t) : 0; - } - lua_unlock(L); - return res; + switch (ttype(o)) { + case LUA_TSTRING: return tsvalue(o)->len; + case LUA_TUSERDATA: return uvalue(o)->len; + case LUA_TTABLE: return luaH_getn(hvalue(o)); + default: return 0; } } @@ -1027,6 +1020,16 @@ LUA_API void lua_concat (lua_State *L, int n) { } +LUA_API void lua_len (lua_State *L, int idx) { + StkId t; + lua_lock(L); + t = index2addr(L, idx); + luaV_objlen(L, L->top, t); + api_incr_top(L); + lua_unlock(L); +} + + LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) { lua_Alloc f; lua_lock(L); -- cgit v1.2.3-55-g6feb