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' --- lauxlib.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'lauxlib.c') diff --git a/lauxlib.c b/lauxlib.c index 7611db7f..dcb913f0 100644 --- a/lauxlib.c +++ b/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.193 2009/10/05 16:44:33 roberto Exp roberto $ +** $Id: lauxlib.c,v 1.194 2009/11/25 15:27:51 roberto Exp roberto $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -370,9 +370,9 @@ static void adjuststack (luaL_Buffer *B) { if (B->lvl > 1) { lua_State *L = B->L; int toget = 1; /* number of levels to concat */ - size_t toplen = lua_objlen(L, -1); + size_t toplen = lua_rawlen(L, -1); do { - size_t l = lua_objlen(L, -(toget+1)); + size_t l = lua_rawlen(L, -(toget+1)); if (B->lvl - toget + 1 >= LIMIT || toplen > l) { toplen += l; toget++; @@ -463,7 +463,7 @@ LUALIB_API int luaL_ref (lua_State *L, int t) { lua_rawseti(L, t, FREELIST_REF); /* (t[FREELIST_REF] = t[ref]) */ } else { /* no free elements */ - ref = (int)lua_objlen(L, t) + 1; /* get a new reference */ + ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */ if (ref == FREELIST_REF) { /* FREELIST_REF not initialized? */ lua_pushinteger(L, 0); lua_rawseti(L, t, FREELIST_REF); @@ -627,6 +627,17 @@ LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) { } +LUALIB_API int luaL_len (lua_State *L, int idx) { + int l; + lua_len(L, idx); + l = lua_tointeger(L, -1); + if (l == 0 && !lua_isnumber(L, -1)) + luaL_error(L, "object length is not a number"); + lua_pop(L, 1); /* remove object */ + return l; +} + + LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { if (!luaL_callmeta(L, idx, "__tostring")) { /* no metafield? */ switch (lua_type(L, idx)) { -- cgit v1.2.3-55-g6feb