aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-01-16 14:54:37 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-01-16 14:54:37 -0200
commit7e2015a46df7976bddee313b994742e49e420714 (patch)
tree0b2db30f1214a478ccb3664d165c8a431f0d5850 /lapi.c
parent5b01cb39b5ec36c544152351c35c43149d9bbfec (diff)
downloadlua-7e2015a46df7976bddee313b994742e49e420714.tar.gz
lua-7e2015a46df7976bddee313b994742e49e420714.tar.bz2
lua-7e2015a46df7976bddee313b994742e49e420714.zip
size of short strings stored in a single byte, to reduce the size
of struct 'TString'
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/lapi.c b/lapi.c
index c2ef6019..9d6123ce 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.243 2014/11/12 13:28:54 roberto Exp roberto $ 2** $Id: lapi.c,v 2.244 2014/12/26 14:43:45 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*/
@@ -382,15 +382,17 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
382 luaO_tostring(L, o); 382 luaO_tostring(L, o);
383 lua_unlock(L); 383 lua_unlock(L);
384 } 384 }
385 if (len != NULL) *len = tsvalue(o)->len; 385 if (len != NULL)
386 *len = vslen(o);
386 return svalue(o); 387 return svalue(o);
387} 388}
388 389
389 390
390LUA_API size_t lua_rawlen (lua_State *L, int idx) { 391LUA_API size_t lua_rawlen (lua_State *L, int idx) {
391 StkId o = index2addr(L, idx); 392 StkId o = index2addr(L, idx);
392 switch (ttnov(o)) { 393 switch (ttype(o)) {
393 case LUA_TSTRING: return tsvalue(o)->len; 394 case LUA_TSHRSTR: return tsvalue(o)->shrlen;
395 case LUA_TLNGSTR: return tsvalue(o)->u.lnglen;
394 case LUA_TUSERDATA: return uvalue(o)->len; 396 case LUA_TUSERDATA: return uvalue(o)->len;
395 case LUA_TTABLE: return luaH_getn(hvalue(o)); 397 case LUA_TTABLE: return luaH_getn(hvalue(o));
396 default: return 0; 398 default: return 0;