From 6b630c0fa0e81ce8c259ab9945604803f04fac3d Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 30 Apr 2014 15:59:15 -0300 Subject: debug.numbits replaced by debug.Csize --- ldblib.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'ldblib.c') diff --git a/ldblib.c b/ldblib.c index 09e1c252..2e0a866b 100644 --- a/ldblib.c +++ b/ldblib.c @@ -1,5 +1,5 @@ /* -** $Id: ldblib.c,v 1.136 2014/02/19 13:51:09 roberto Exp roberto $ +** $Id: ldblib.c,v 1.137 2014/03/12 20:57:40 roberto Exp roberto $ ** Interface from Lua to its debug API ** See Copyright Notice in lua.h */ @@ -21,16 +21,30 @@ #define HOOKKEY "_HKEY" - -static int db_numbits (lua_State *L) { +static int db_Csize (lua_State *L) { + static struct { + char c; + unsigned char sz; + } sizes[] = { + {'I', sizeof(lua_Integer)}, + {'F', sizeof(lua_Number)}, + {'b', CHAR_BIT}, + {'h', sizeof(short)}, + {'i', sizeof(int)}, + {'l', sizeof(long)}, + {'z', sizeof(size_t)}, + {'f', sizeof(float)}, + {'d', sizeof(double)} + }; const char *s = luaL_checkstring(L, 1); - if (*s == 'i') - lua_pushinteger(L, sizeof(lua_Integer) * CHAR_BIT); - else if (*s == 'f') - lua_pushinteger(L, sizeof(lua_Number) * CHAR_BIT); - else - luaL_argerror(L, 1, lua_pushfstring(L, "invalid option '%s'", s)); - return 1; + int i; + for (i = 0; i < (int)(sizeof(sizes)/sizeof(sizes[0])); i++) { + if (*s == sizes[i].c) { + lua_pushinteger(L, sizes[i].sz); + return 1; + } + } + return luaL_argerror(L, 1, lua_pushfstring(L, "invalid option '%c'", *s)); } @@ -379,6 +393,7 @@ static int db_traceback (lua_State *L) { static const luaL_Reg dblib[] = { + {"Csize", db_Csize}, {"debug", db_debug}, {"getuservalue", db_getuservalue}, {"gethook", db_gethook}, @@ -387,7 +402,6 @@ static const luaL_Reg dblib[] = { {"getregistry", db_getregistry}, {"getmetatable", db_getmetatable}, {"getupvalue", db_getupvalue}, - {"numbits", db_numbits}, {"upvaluejoin", db_upvaluejoin}, {"upvalueid", db_upvalueid}, {"setuservalue", db_setuservalue}, -- cgit v1.2.3-55-g6feb