aboutsummaryrefslogtreecommitdiff
path: root/ldblib.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldblib.c')
-rw-r--r--ldblib.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/ldblib.c b/ldblib.c
index 09e1c252..2e0a866b 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldblib.c,v 1.136 2014/02/19 13:51:09 roberto Exp roberto $ 2** $Id: ldblib.c,v 1.137 2014/03/12 20:57:40 roberto Exp roberto $
3** Interface from Lua to its debug API 3** Interface from Lua to its debug API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -21,16 +21,30 @@
21#define HOOKKEY "_HKEY" 21#define HOOKKEY "_HKEY"
22 22
23 23
24 24static int db_Csize (lua_State *L) {
25static int db_numbits (lua_State *L) { 25 static struct {
26 char c;
27 unsigned char sz;
28 } sizes[] = {
29 {'I', sizeof(lua_Integer)},
30 {'F', sizeof(lua_Number)},
31 {'b', CHAR_BIT},
32 {'h', sizeof(short)},
33 {'i', sizeof(int)},
34 {'l', sizeof(long)},
35 {'z', sizeof(size_t)},
36 {'f', sizeof(float)},
37 {'d', sizeof(double)}
38 };
26 const char *s = luaL_checkstring(L, 1); 39 const char *s = luaL_checkstring(L, 1);
27 if (*s == 'i') 40 int i;
28 lua_pushinteger(L, sizeof(lua_Integer) * CHAR_BIT); 41 for (i = 0; i < (int)(sizeof(sizes)/sizeof(sizes[0])); i++) {
29 else if (*s == 'f') 42 if (*s == sizes[i].c) {
30 lua_pushinteger(L, sizeof(lua_Number) * CHAR_BIT); 43 lua_pushinteger(L, sizes[i].sz);
31 else 44 return 1;
32 luaL_argerror(L, 1, lua_pushfstring(L, "invalid option '%s'", s)); 45 }
33 return 1; 46 }
47 return luaL_argerror(L, 1, lua_pushfstring(L, "invalid option '%c'", *s));
34} 48}
35 49
36 50
@@ -379,6 +393,7 @@ static int db_traceback (lua_State *L) {
379 393
380 394
381static const luaL_Reg dblib[] = { 395static const luaL_Reg dblib[] = {
396 {"Csize", db_Csize},
382 {"debug", db_debug}, 397 {"debug", db_debug},
383 {"getuservalue", db_getuservalue}, 398 {"getuservalue", db_getuservalue},
384 {"gethook", db_gethook}, 399 {"gethook", db_gethook},
@@ -387,7 +402,6 @@ static const luaL_Reg dblib[] = {
387 {"getregistry", db_getregistry}, 402 {"getregistry", db_getregistry},
388 {"getmetatable", db_getmetatable}, 403 {"getmetatable", db_getmetatable},
389 {"getupvalue", db_getupvalue}, 404 {"getupvalue", db_getupvalue},
390 {"numbits", db_numbits},
391 {"upvaluejoin", db_upvaluejoin}, 405 {"upvaluejoin", db_upvaluejoin},
392 {"upvalueid", db_upvalueid}, 406 {"upvalueid", db_upvalueid},
393 {"setuservalue", db_setuservalue}, 407 {"setuservalue", db_setuservalue},