aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-12-17 14:20:01 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-12-17 14:20:01 -0200
commitc3a6f3fa1c6360d4ea2e32f9415f51e8e55093b4 (patch)
tree9f26c632fa0215c21260a81f6fad1a79678f8173 /lapi.c
parent0bbdddc86b1353fec36ae886b4142986f3c4713f (diff)
downloadlua-c3a6f3fa1c6360d4ea2e32f9415f51e8e55093b4.tar.gz
lua-c3a6f3fa1c6360d4ea2e32f9415f51e8e55093b4.tar.bz2
lua-c3a6f3fa1c6360d4ea2e32f9415f51e8e55093b4.zip
'lua_objlen' replaced by 'lua_rawlen', 'lua_len', and 'luaL_len'
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/lapi.c b/lapi.c
index b26efbc0..3b24d70c 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.103 2009/12/08 16:15:43 roberto Exp roberto $ 2** $Id: lapi.c,v 2.104 2009/12/15 11:25:36 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*/
@@ -374,20 +374,13 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
374} 374}
375 375
376 376
377LUA_API size_t lua_objlen (lua_State *L, int idx) { 377LUA_API size_t lua_rawlen (lua_State *L, int idx) {
378 StkId o = index2addr(L, idx); 378 StkId o = index2addr(L, idx);
379 if (ttisuserdata(o)) return uvalue(o)->len; 379 switch (ttype(o)) {
380 else { 380 case LUA_TSTRING: return tsvalue(o)->len;
381 size_t res; 381 case LUA_TUSERDATA: return uvalue(o)->len;
382 TValue temp; 382 case LUA_TTABLE: return luaH_getn(hvalue(o));
383 lua_lock(L); 383 default: return 0;
384 res = luaV_len(L, o, &temp);
385 if (res == cast(size_t, -1)) {
386 const TValue *t = &temp;
387 res = tonumber(t, &temp) ? nvalue(t) : 0;
388 }
389 lua_unlock(L);
390 return res;
391 } 384 }
392} 385}
393 386
@@ -1027,6 +1020,16 @@ LUA_API void lua_concat (lua_State *L, int n) {
1027} 1020}
1028 1021
1029 1022
1023LUA_API void lua_len (lua_State *L, int idx) {
1024 StkId t;
1025 lua_lock(L);
1026 t = index2addr(L, idx);
1027 luaV_objlen(L, L->top, t);
1028 api_incr_top(L);
1029 lua_unlock(L);
1030}
1031
1032
1030LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) { 1033LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {
1031 lua_Alloc f; 1034 lua_Alloc f;
1032 lua_lock(L); 1035 lua_lock(L);