summaryrefslogtreecommitdiff
path: root/src/ldblib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ldblib.c')
-rw-r--r--src/ldblib.c114
1 files changed, 59 insertions, 55 deletions
diff --git a/src/ldblib.c b/src/ldblib.c
index 7f8bde1f..6c1a1776 100644
--- a/src/ldblib.c
+++ b/src/ldblib.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldblib.c,v 1.93 2005/02/18 12:40:02 roberto Exp $
+** $Id: ldblib.c,v 1.98 2005/05/17 19:49:15 roberto Exp $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@@ -19,7 +19,7 @@
-static int getmetatable (lua_State *L) {
+static int db_getmetatable (lua_State *L) {
luaL_checkany(L, 1);
if (!lua_getmetatable(L, 1)) {
lua_pushnil(L); /* no metatable */
@@ -28,7 +28,7 @@ static int getmetatable (lua_State *L) {
}
-static int setmetatable (lua_State *L) {
+static int db_setmetatable (lua_State *L) {
int t = lua_type(L, 2);
luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2,
"nil or table expected");
@@ -38,17 +38,18 @@ static int setmetatable (lua_State *L) {
}
-static int getfenv (lua_State *L) {
+static int db_getfenv (lua_State *L) {
lua_getfenv(L, 1);
return 1;
}
-static int setfenv (lua_State *L) {
+static int db_setfenv (lua_State *L) {
luaL_checktype(L, 2, LUA_TTABLE);
lua_settop(L, 2);
if (lua_setfenv(L, 1) == 0)
- luaL_error(L, "`setfenv' cannot change environment of given object");
+ luaL_error(L, LUA_QL("setfenv")
+ " cannot change environment of given object");
return 1;
}
@@ -77,7 +78,18 @@ static lua_State *getthread (lua_State *L, int *arg) {
}
-static int getinfo (lua_State *L) {
+static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {
+ if (L == L1) {
+ lua_pushvalue(L, -2);
+ lua_remove(L, -3);
+ }
+ else
+ lua_xmove(L1, L, 1);
+ lua_setfield(L, -2, fname);
+}
+
+
+static int db_getinfo (lua_State *L) {
lua_Debug ar;
int arg;
lua_State *L1 = getthread(L, &arg);
@@ -99,38 +111,30 @@ static int getinfo (lua_State *L) {
if (!lua_getinfo(L1, options, &ar))
return luaL_argerror(L, arg+2, "invalid option");
lua_newtable(L);
- for (; *options; options++) {
- switch (*options) {
- case 'S':
- settabss(L, "source", ar.source);
- settabss(L, "short_src", ar.short_src);
- settabsi(L, "linedefined", ar.linedefined);
- settabss(L, "what", ar.what);
- break;
- case 'l':
- settabsi(L, "currentline", ar.currentline);
- break;
- case 'u':
- settabsi(L, "nups", ar.nups);
- break;
- case 'n':
- settabss(L, "name", ar.name);
- settabss(L, "namewhat", ar.namewhat);
- break;
- case 'f':
- if (L == L1)
- lua_pushvalue(L, -2);
- else
- lua_xmove(L1, L, 1);
- lua_setfield(L, -2, "func");
- break;
- }
+ if (strchr(options, 'S')) {
+ settabss(L, "source", ar.source);
+ settabss(L, "short_src", ar.short_src);
+ settabsi(L, "linedefined", ar.linedefined);
+ settabsi(L, "lastlinedefined", ar.lastlinedefined);
+ settabss(L, "what", ar.what);
+ }
+ if (strchr(options, 'l'))
+ settabsi(L, "currentline", ar.currentline);
+ if (strchr(options, 'u'))
+ settabsi(L, "nups", ar.nups);
+ if (strchr(options, 'n')) {
+ settabss(L, "name", ar.name);
+ settabss(L, "namewhat", ar.namewhat);
}
+ if (strchr(options, 'L'))
+ treatstackoption(L, L1, "activelines");
+ if (strchr(options, 'f'))
+ treatstackoption(L, L1, "func");
return 1; /* return table */
}
-static int getlocal (lua_State *L) {
+static int db_getlocal (lua_State *L) {
int arg;
lua_State *L1 = getthread(L, &arg);
lua_Debug ar;
@@ -151,7 +155,7 @@ static int getlocal (lua_State *L) {
}
-static int setlocal (lua_State *L) {
+static int db_setlocal (lua_State *L) {
int arg;
lua_State *L1 = getthread(L, &arg);
lua_Debug ar;
@@ -178,12 +182,12 @@ static int auxupvalue (lua_State *L, int get) {
}
-static int getupvalue (lua_State *L) {
+static int db_getupvalue (lua_State *L) {
return auxupvalue(L, 1);
}
-static int setupvalue (lua_State *L) {
+static int db_setupvalue (lua_State *L) {
luaL_checkany(L, 3);
return auxupvalue(L, 0);
}
@@ -244,7 +248,7 @@ static void gethooktable (lua_State *L) {
}
-static int sethook (lua_State *L) {
+static int db_sethook (lua_State *L) {
int arg;
lua_State *L1 = getthread(L, &arg);
if (lua_isnoneornil(L, arg+1)) {
@@ -267,7 +271,7 @@ static int sethook (lua_State *L) {
}
-static int gethook (lua_State *L) {
+static int db_gethook (lua_State *L) {
int arg;
lua_State *L1 = getthread(L, &arg);
char buff[5];
@@ -288,7 +292,7 @@ static int gethook (lua_State *L) {
}
-static int debug (lua_State *L) {
+static int db_debug (lua_State *L) {
for (;;) {
char buffer[250];
fputs("lua_debug> ", stderr);
@@ -308,7 +312,7 @@ static int debug (lua_State *L) {
#define LEVELS1 12 /* size of the first part of the stack */
#define LEVELS2 10 /* size of the second part of the stack */
-static int errorfb (lua_State *L) {
+static int db_errorfb (lua_State *L) {
int level;
int firstpart = 1; /* still before eventual `...' */
int arg;
@@ -344,7 +348,7 @@ static int errorfb (lua_State *L) {
if (ar.currentline > 0)
lua_pushfstring(L, "%d:", ar.currentline);
if (*ar.namewhat != '\0') /* is there a name? */
- lua_pushfstring(L, " in function `%s'", ar.name);
+ lua_pushfstring(L, " in function " LUA_QS, ar.name);
else {
if (*ar.what == 'm') /* main? */
lua_pushfstring(L, " in main chunk");
@@ -362,19 +366,19 @@ static int errorfb (lua_State *L) {
static const luaL_reg dblib[] = {
- {"getmetatable", getmetatable},
- {"setmetatable", setmetatable},
- {"getfenv", getfenv},
- {"setfenv", setfenv},
- {"getlocal", getlocal},
- {"getinfo", getinfo},
- {"gethook", gethook},
- {"getupvalue", getupvalue},
- {"sethook", sethook},
- {"setlocal", setlocal},
- {"setupvalue", setupvalue},
- {"debug", debug},
- {"traceback", errorfb},
+ {"getmetatable", db_getmetatable},
+ {"setmetatable", db_setmetatable},
+ {"getfenv", db_getfenv},
+ {"setfenv", db_setfenv},
+ {"getlocal", db_getlocal},
+ {"getinfo", db_getinfo},
+ {"gethook", db_gethook},
+ {"getupvalue", db_getupvalue},
+ {"sethook", db_sethook},
+ {"setlocal", db_setlocal},
+ {"setupvalue", db_setupvalue},
+ {"debug", db_debug},
+ {"traceback", db_errorfb},
{NULL, NULL}
};