lua_strlen' upgraded to lua_objsize' (which also works with userdata)

This commit is contained in:
Roberto Ierusalimschy
2004-05-31 16:41:52 -03:00
parent 1e0aaf2156
commit 0dfd04eb60
3 changed files with 11 additions and 23 deletions

6
lapi.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 2.8 2004/05/11 16:52:08 roberto Exp roberto $
** $Id: lapi.c,v 2.9 2004/05/14 19:25:09 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@@ -323,10 +323,12 @@ LUA_API const char *lua_tostring (lua_State *L, int idx) {
}
LUA_API size_t lua_strlen (lua_State *L, int idx) {
LUA_API size_t lua_objsize (lua_State *L, int idx) {
StkId o = luaA_index(L, idx);
if (ttisstring(o))
return tsvalue(o)->len;
else if (ttisuserdata(o))
return uvalue(o)->len;
else {
size_t l;
lua_lock(L); /* `luaV_tostring' may create a new string */