diff options
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 24 |
1 files changed, 13 insertions, 11 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.30 2005/03/08 20:10:05 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.31 2005/03/09 16:28:07 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -350,16 +350,18 @@ LUA_API const char *lua_tostring (lua_State *L, int idx) { | |||
| 350 | 350 | ||
| 351 | LUA_API size_t lua_objsize (lua_State *L, int idx) { | 351 | LUA_API size_t lua_objsize (lua_State *L, int idx) { |
| 352 | StkId o = index2adr(L, idx); | 352 | StkId o = index2adr(L, idx); |
| 353 | if (ttisstring(o)) | 353 | switch (ttype(o)) { |
| 354 | return tsvalue(o)->len; | 354 | case LUA_TSTRING: return tsvalue(o)->len; |
| 355 | else if (ttisuserdata(o)) | 355 | case LUA_TUSERDATA: return uvalue(o)->len; |
| 356 | return uvalue(o)->len; | 356 | case LUA_TTABLE: return luaH_getn(hvalue(o)); |
| 357 | else { | 357 | case LUA_TNUMBER: { |
| 358 | size_t l; | 358 | size_t l; |
| 359 | lua_lock(L); /* `luaV_tostring' may create a new string */ | 359 | lua_lock(L); /* `luaV_tostring' may create a new string */ |
| 360 | l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0); | 360 | l = (luaV_tostring(L, o) ? tsvalue(o)->len : 0); |
| 361 | lua_unlock(L); | 361 | lua_unlock(L); |
| 362 | return l; | 362 | return l; |
| 363 | } | ||
| 364 | default: return 0; | ||
| 363 | } | 365 | } |
| 364 | } | 366 | } |
| 365 | 367 | ||
