Commit a08626d8 authored by TerryE's avatar TerryE
Browse files

Add minimum debug library providing traceback() and getregistry() functions

parent 95e2bbb0
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
// #define LUA_USE_BUILTIN_IO // for io.xxx(), partially work // #define LUA_USE_BUILTIN_IO // for io.xxx(), partially work
// #define LUA_USE_BUILTIN_OS // for os.xxx(), not work // #define LUA_USE_BUILTIN_OS // for os.xxx(), not work
// #define LUA_USE_BUILTIN_DEBUG // for debug.xxx(), not work // #define LUA_USE_BUILTIN_DEBUG
#define LUA_USE_BUILTIN_DEBUG_MINIMAL // for debug.getregistry() and debug.traceback()
#define LUA_USE_MODULES #define LUA_USE_MODULES
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "lualib.h" #include "lualib.h"
#include "lrotable.h" #include "lrotable.h"
#include "user_modules.h"
...@@ -25,6 +26,7 @@ static int db_getregistry (lua_State *L) { ...@@ -25,6 +26,7 @@ static int db_getregistry (lua_State *L) {
return 1; return 1;
} }
#ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
static int db_getmetatable (lua_State *L) { static int db_getmetatable (lua_State *L) {
luaL_checkany(L, 1); luaL_checkany(L, 1);
...@@ -73,7 +75,7 @@ static void settabsi (lua_State *L, const char *i, int v) { ...@@ -73,7 +75,7 @@ static void settabsi (lua_State *L, const char *i, int v) {
lua_setfield(L, -2, i); lua_setfield(L, -2, i);
} }
#endif
static lua_State *getthread (lua_State *L, int *arg) { static lua_State *getthread (lua_State *L, int *arg) {
if (lua_isthread(L, 1)) { if (lua_isthread(L, 1)) {
*arg = 1; *arg = 1;
...@@ -84,7 +86,7 @@ static lua_State *getthread (lua_State *L, int *arg) { ...@@ -84,7 +86,7 @@ static lua_State *getthread (lua_State *L, int *arg) {
return L; return L;
} }
} }
#ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) { static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {
if (L == L1) { if (L == L1) {
...@@ -324,7 +326,7 @@ static int db_debug (lua_State *L) { ...@@ -324,7 +326,7 @@ static int db_debug (lua_State *L) {
lua_settop(L, 0); /* remove eventual returns */ lua_settop(L, 0); /* remove eventual returns */
} }
} }
#endif
#define LEVELS1 12 /* size of the first part of the stack */ #define LEVELS1 12 /* size of the first part of the stack */
#define LEVELS2 10 /* size of the second part of the stack */ #define LEVELS2 10 /* size of the second part of the stack */
...@@ -384,12 +386,15 @@ static int db_errorfb (lua_State *L) { ...@@ -384,12 +386,15 @@ static int db_errorfb (lua_State *L) {
#define MIN_OPT_LEVEL 1 #define MIN_OPT_LEVEL 1
#include "lrodefs.h" #include "lrodefs.h"
const LUA_REG_TYPE dblib[] = { const LUA_REG_TYPE dblib[] = {
#ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
{LSTRKEY("debug"), LFUNCVAL(db_debug)}, {LSTRKEY("debug"), LFUNCVAL(db_debug)},
{LSTRKEY("getfenv"), LFUNCVAL(db_getfenv)}, {LSTRKEY("getfenv"), LFUNCVAL(db_getfenv)},
{LSTRKEY("gethook"), LFUNCVAL(db_gethook)}, {LSTRKEY("gethook"), LFUNCVAL(db_gethook)},
{LSTRKEY("getinfo"), LFUNCVAL(db_getinfo)}, {LSTRKEY("getinfo"), LFUNCVAL(db_getinfo)},
{LSTRKEY("getlocal"), LFUNCVAL(db_getlocal)}, {LSTRKEY("getlocal"), LFUNCVAL(db_getlocal)},
#endif
{LSTRKEY("getregistry"), LFUNCVAL(db_getregistry)}, {LSTRKEY("getregistry"), LFUNCVAL(db_getregistry)},
#ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
{LSTRKEY("getmetatable"), LFUNCVAL(db_getmetatable)}, {LSTRKEY("getmetatable"), LFUNCVAL(db_getmetatable)},
{LSTRKEY("getupvalue"), LFUNCVAL(db_getupvalue)}, {LSTRKEY("getupvalue"), LFUNCVAL(db_getupvalue)},
{LSTRKEY("setfenv"), LFUNCVAL(db_setfenv)}, {LSTRKEY("setfenv"), LFUNCVAL(db_setfenv)},
...@@ -397,6 +402,7 @@ const LUA_REG_TYPE dblib[] = { ...@@ -397,6 +402,7 @@ const LUA_REG_TYPE dblib[] = {
{LSTRKEY("setlocal"), LFUNCVAL(db_setlocal)}, {LSTRKEY("setlocal"), LFUNCVAL(db_setlocal)},
{LSTRKEY("setmetatable"), LFUNCVAL(db_setmetatable)}, {LSTRKEY("setmetatable"), LFUNCVAL(db_setmetatable)},
{LSTRKEY("setupvalue"), LFUNCVAL(db_setupvalue)}, {LSTRKEY("setupvalue"), LFUNCVAL(db_setupvalue)},
#endif
{LSTRKEY("traceback"), LFUNCVAL(db_errorfb)}, {LSTRKEY("traceback"), LFUNCVAL(db_errorfb)},
{LNILKEY, LNILVAL} {LNILKEY, LNILVAL}
}; };
......
...@@ -47,7 +47,7 @@ static const luaL_Reg lualibs[] = { ...@@ -47,7 +47,7 @@ static const luaL_Reg lualibs[] = {
{LUA_TABLIBNAME, luaopen_table}, {LUA_TABLIBNAME, luaopen_table},
#endif #endif
#if defined(LUA_USE_BUILTIN_DEBUG) #if defined(LUA_USE_BUILTIN_DEBUG) || defined(LUA_USE_BUILTIN_DEBUG_MINIMAL)
{LUA_DBLIBNAME, luaopen_debug}, {LUA_DBLIBNAME, luaopen_debug},
#endif #endif
#endif #endif
...@@ -71,7 +71,7 @@ extern const luaR_entry syslib[]; ...@@ -71,7 +71,7 @@ extern const luaR_entry syslib[];
extern const luaR_entry tab_funcs[]; extern const luaR_entry tab_funcs[];
#endif #endif
#if defined(LUA_USE_BUILTIN_DEBUG) #if defined(LUA_USE_BUILTIN_DEBUG) || defined(LUA_USE_BUILTIN_DEBUG_MINIMAL)
extern const luaR_entry dblib[]; extern const luaR_entry dblib[];
#endif #endif
...@@ -99,7 +99,7 @@ const luaR_table lua_rotable[] = ...@@ -99,7 +99,7 @@ const luaR_table lua_rotable[] =
{LUA_TABLIBNAME, tab_funcs}, {LUA_TABLIBNAME, tab_funcs},
#endif #endif
#if defined(LUA_USE_BUILTIN_DEBUG) #if defined(LUA_USE_BUILTIN_DEBUG) || defined(LUA_USE_BUILTIN_DEBUG_MINIMAL)
{LUA_DBLIBNAME, dblib}, {LUA_DBLIBNAME, dblib},
#endif #endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment