From eb9ad22e7538a25ef565e93c842eef48dba2469e Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 22 Feb 2017 14:19:19 +0100 Subject: lua_rawlen, rawlen --- src/lapi.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/lapi.js') diff --git a/src/lapi.js b/src/lapi.js index 19e3090..76dee1b 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -464,6 +464,21 @@ const lua_tolstring = function(L, idx) { const lua_tostring = lua_tolstring; +const lua_rawlen = function(L, idx) { + let o = index2addr(L, idx); + switch (o.ttype()) { + case CT.LUA_TSHRSTR: + case CT.LUA_TLNGSTR: + return o.value.length; + case CT.LUA_TUSERDATA: + return o.len; + case CT.LUA_TTABLE: + return o.luaH_getn(); + default: + return 0; + } +}; + const lua_tointeger = function(L, idx) { return lvm.tointeger(index2addr(L, idx)) }; @@ -694,6 +709,7 @@ module.exports.lua_absindex = lua_absindex; module.exports.index2addr = index2addr; module.exports.lua_rawget = lua_rawget; module.exports.lua_rawset = lua_rawset; +module.exports.lua_rawlen = lua_rawlen; module.exports.lua_isstring = lua_isstring; module.exports.lua_rotate = lua_rotate; module.exports.lua_remove = lua_remove; -- cgit v1.2.3-54-g00ecf