diff options
Diffstat (limited to 'ldblib.c')
-rw-r--r-- | ldblib.c | 22 |
1 files changed, 8 insertions, 14 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldblib.c,v 1.40 2001/10/26 17:33:30 roberto Exp $ | 2 | ** $Id: ldblib.c,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $ |
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 | */ |
@@ -18,16 +18,14 @@ | |||
18 | 18 | ||
19 | 19 | ||
20 | static void settabss (lua_State *L, const char *i, const char *v) { | 20 | static void settabss (lua_State *L, const char *i, const char *v) { |
21 | lua_pushstring(L, i); | ||
22 | lua_pushstring(L, v); | 21 | lua_pushstring(L, v); |
23 | lua_settable(L, -3); | 22 | lua_setstr(L, -2, i); |
24 | } | 23 | } |
25 | 24 | ||
26 | 25 | ||
27 | static void settabsi (lua_State *L, const char *i, int v) { | 26 | static void settabsi (lua_State *L, const char *i, int v) { |
28 | lua_pushstring(L, i); | ||
29 | lua_pushnumber(L, v); | 27 | lua_pushnumber(L, v); |
30 | lua_settable(L, -3); | 28 | lua_setstr(L, -2, i); |
31 | } | 29 | } |
32 | 30 | ||
33 | 31 | ||
@@ -71,9 +69,8 @@ static int getinfo (lua_State *L) { | |||
71 | settabss(L, "namewhat", ar.namewhat); | 69 | settabss(L, "namewhat", ar.namewhat); |
72 | break; | 70 | break; |
73 | case 'f': | 71 | case 'f': |
74 | lua_pushliteral(L, "func"); | 72 | lua_pushvalue(L, -2); |
75 | lua_pushvalue(L, -3); | 73 | lua_setstr(L, -2, "func"); |
76 | lua_settable(L, -3); | ||
77 | break; | 74 | break; |
78 | } | 75 | } |
79 | } | 76 | } |
@@ -115,8 +112,7 @@ static int setlocal (lua_State *L) { | |||
115 | 112 | ||
116 | 113 | ||
117 | static void hookf (lua_State *L, const char *key) { | 114 | static void hookf (lua_State *L, const char *key) { |
118 | lua_pushstring(L, key); | 115 | lua_getstr(L, LUA_REGISTRYINDEX, key); |
119 | lua_gettable(L, LUA_REGISTRYINDEX); | ||
120 | if (lua_isfunction(L, -1)) { | 116 | if (lua_isfunction(L, -1)) { |
121 | lua_pushvalue(L, -2); /* original argument (below function) */ | 117 | lua_pushvalue(L, -2); /* original argument (below function) */ |
122 | lua_rawcall(L, 1, 0); | 118 | lua_rawcall(L, 1, 0); |
@@ -147,11 +143,9 @@ static void sethook (lua_State *L, const char *key, lua_Hook hook, | |||
147 | (*sethookf)(L, hook); | 143 | (*sethookf)(L, hook); |
148 | else | 144 | else |
149 | luaL_argerror(L, 1, "function expected"); | 145 | luaL_argerror(L, 1, "function expected"); |
150 | lua_pushstring(L, key); | 146 | lua_getstr(L, LUA_REGISTRYINDEX, key); /* get old value */ |
151 | lua_gettable(L, LUA_REGISTRYINDEX); /* get old value */ | ||
152 | lua_pushstring(L, key); | ||
153 | lua_pushvalue(L, 1); | 147 | lua_pushvalue(L, 1); |
154 | lua_settable(L, LUA_REGISTRYINDEX); /* set new value */ | 148 | lua_setstr(L, LUA_REGISTRYINDEX, key); /* set new value */ |
155 | } | 149 | } |
156 | 150 | ||
157 | 151 | ||