diff options
Diffstat (limited to '')
| -rw-r--r-- | ldblib.c | 71 |
1 files changed, 35 insertions, 36 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldblib.c,v 1.39 2001/10/17 21:12:57 roberto Exp $ | 2 | ** $Id: ldblib.c,v 1.40 2001/10/26 17:33:30 roberto Exp $ |
| 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 | */ |
| @@ -9,7 +9,6 @@ | |||
| 9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
| 10 | #include <string.h> | 10 | #include <string.h> |
| 11 | 11 | ||
| 12 | #define LUA_PRIVATE | ||
| 13 | #include "lua.h" | 12 | #include "lua.h" |
| 14 | 13 | ||
| 15 | #include "lauxlib.h" | 14 | #include "lauxlib.h" |
| @@ -18,14 +17,14 @@ | |||
| 18 | 17 | ||
| 19 | 18 | ||
| 20 | 19 | ||
| 21 | static void settabss (lua_State *L, const l_char *i, const l_char *v) { | 20 | static void settabss (lua_State *L, const char *i, const char *v) { |
| 22 | lua_pushstring(L, i); | 21 | lua_pushstring(L, i); |
| 23 | lua_pushstring(L, v); | 22 | lua_pushstring(L, v); |
| 24 | lua_settable(L, -3); | 23 | lua_settable(L, -3); |
| 25 | } | 24 | } |
| 26 | 25 | ||
| 27 | 26 | ||
| 28 | static void settabsi (lua_State *L, const l_char *i, int v) { | 27 | static void settabsi (lua_State *L, const char *i, int v) { |
| 29 | lua_pushstring(L, i); | 28 | lua_pushstring(L, i); |
| 30 | lua_pushnumber(L, v); | 29 | lua_pushnumber(L, v); |
| 31 | lua_settable(L, -3); | 30 | lua_settable(L, -3); |
| @@ -34,8 +33,8 @@ static void settabsi (lua_State *L, const l_char *i, int v) { | |||
| 34 | 33 | ||
| 35 | static int getinfo (lua_State *L) { | 34 | static int getinfo (lua_State *L) { |
| 36 | lua_Debug ar; | 35 | lua_Debug ar; |
| 37 | const l_char *options = luaL_opt_string(L, 2, l_s("flnSu")); | 36 | const char *options = luaL_opt_string(L, 2, "flnSu"); |
| 38 | l_char buff[20]; | 37 | char buff[20]; |
| 39 | if (lua_isnumber(L, 1)) { | 38 | if (lua_isnumber(L, 1)) { |
| 40 | if (!lua_getstack(L, (int)(lua_tonumber(L, 1)), &ar)) { | 39 | if (!lua_getstack(L, (int)(lua_tonumber(L, 1)), &ar)) { |
| 41 | lua_pushnil(L); /* level out of range */ | 40 | lua_pushnil(L); /* level out of range */ |
| @@ -44,35 +43,35 @@ static int getinfo (lua_State *L) { | |||
| 44 | } | 43 | } |
| 45 | else if (lua_isfunction(L, 1)) { | 44 | else if (lua_isfunction(L, 1)) { |
| 46 | lua_pushvalue(L, 1); | 45 | lua_pushvalue(L, 1); |
| 47 | sprintf(buff, l_s(">%.10s"), options); | 46 | sprintf(buff, ">%.10s", options); |
| 48 | options = buff; | 47 | options = buff; |
| 49 | } | 48 | } |
| 50 | else | 49 | else |
| 51 | luaL_argerror(L, 1, l_s("function or level expected")); | 50 | luaL_argerror(L, 1, "function or level expected"); |
| 52 | if (!lua_getinfo(L, options, &ar)) | 51 | if (!lua_getinfo(L, options, &ar)) |
| 53 | luaL_argerror(L, 2, l_s("invalid option")); | 52 | luaL_argerror(L, 2, "invalid option"); |
| 54 | lua_newtable(L); | 53 | lua_newtable(L); |
| 55 | for (; *options; options++) { | 54 | for (; *options; options++) { |
| 56 | switch (*options) { | 55 | switch (*options) { |
| 57 | case l_c('S'): | 56 | case 'S': |
| 58 | settabss(L, l_s("source"), ar.source); | 57 | settabss(L, "source", ar.source); |
| 59 | if (ar.source) | 58 | if (ar.source) |
| 60 | settabss(L, l_s("short_src"), ar.short_src); | 59 | settabss(L, "short_src", ar.short_src); |
| 61 | settabsi(L, l_s("linedefined"), ar.linedefined); | 60 | settabsi(L, "linedefined", ar.linedefined); |
| 62 | settabss(L, l_s("what"), ar.what); | 61 | settabss(L, "what", ar.what); |
| 63 | break; | 62 | break; |
| 64 | case l_c('l'): | 63 | case 'l': |
| 65 | settabsi(L, l_s("currentline"), ar.currentline); | 64 | settabsi(L, "currentline", ar.currentline); |
| 66 | break; | 65 | break; |
| 67 | case l_c('u'): | 66 | case 'u': |
| 68 | settabsi(L, l_s("nups"), ar.nups); | 67 | settabsi(L, "nups", ar.nups); |
| 69 | break; | 68 | break; |
| 70 | case l_c('n'): | 69 | case 'n': |
| 71 | settabss(L, l_s("name"), ar.name); | 70 | settabss(L, "name", ar.name); |
| 72 | settabss(L, l_s("namewhat"), ar.namewhat); | 71 | settabss(L, "namewhat", ar.namewhat); |
| 73 | break; | 72 | break; |
| 74 | case l_c('f'): | 73 | case 'f': |
| 75 | lua_pushliteral(L, l_s("func")); | 74 | lua_pushliteral(L, "func"); |
| 76 | lua_pushvalue(L, -3); | 75 | lua_pushvalue(L, -3); |
| 77 | lua_settable(L, -3); | 76 | lua_settable(L, -3); |
| 78 | break; | 77 | break; |
| @@ -84,9 +83,9 @@ static int getinfo (lua_State *L) { | |||
| 84 | 83 | ||
| 85 | static int getlocal (lua_State *L) { | 84 | static int getlocal (lua_State *L) { |
| 86 | lua_Debug ar; | 85 | lua_Debug ar; |
| 87 | const l_char *name; | 86 | const char *name; |
| 88 | if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ | 87 | if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ |
| 89 | luaL_argerror(L, 1, l_s("level out of range")); | 88 | luaL_argerror(L, 1, "level out of range"); |
| 90 | name = lua_getlocal(L, &ar, luaL_check_int(L, 2)); | 89 | name = lua_getlocal(L, &ar, luaL_check_int(L, 2)); |
| 91 | if (name) { | 90 | if (name) { |
| 92 | lua_pushstring(L, name); | 91 | lua_pushstring(L, name); |
| @@ -103,7 +102,7 @@ static int getlocal (lua_State *L) { | |||
| 103 | static int setlocal (lua_State *L) { | 102 | static int setlocal (lua_State *L) { |
| 104 | lua_Debug ar; | 103 | lua_Debug ar; |
| 105 | if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ | 104 | if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */ |
| 106 | luaL_argerror(L, 1, l_s("level out of range")); | 105 | luaL_argerror(L, 1, "level out of range"); |
| 107 | luaL_check_any(L, 3); | 106 | luaL_check_any(L, 3); |
| 108 | lua_pushstring(L, lua_setlocal(L, &ar, luaL_check_int(L, 2))); | 107 | lua_pushstring(L, lua_setlocal(L, &ar, luaL_check_int(L, 2))); |
| 109 | return 1; | 108 | return 1; |
| @@ -111,11 +110,11 @@ static int setlocal (lua_State *L) { | |||
| 111 | 110 | ||
| 112 | 111 | ||
| 113 | 112 | ||
| 114 | #define KEY_CALLHOOK l_s("luadblibCallhook") | 113 | #define KEY_CALLHOOK "luadblibCallhook" |
| 115 | #define KEY_LINEHOOK l_s("luadblibLinehook") | 114 | #define KEY_LINEHOOK "luadblibLinehook" |
| 116 | 115 | ||
| 117 | 116 | ||
| 118 | static void hookf (lua_State *L, const l_char *key) { | 117 | static void hookf (lua_State *L, const char *key) { |
| 119 | lua_pushstring(L, key); | 118 | lua_pushstring(L, key); |
| 120 | lua_gettable(L, LUA_REGISTRYINDEX); | 119 | lua_gettable(L, LUA_REGISTRYINDEX); |
| 121 | if (lua_isfunction(L, -1)) { | 120 | if (lua_isfunction(L, -1)) { |
| @@ -139,7 +138,7 @@ static void linef (lua_State *L, lua_Debug *ar) { | |||
| 139 | } | 138 | } |
| 140 | 139 | ||
| 141 | 140 | ||
| 142 | static void sethook (lua_State *L, const l_char *key, lua_Hook hook, | 141 | static void sethook (lua_State *L, const char *key, lua_Hook hook, |
| 143 | lua_Hook (*sethookf)(lua_State * L, lua_Hook h)) { | 142 | lua_Hook (*sethookf)(lua_State * L, lua_Hook h)) { |
| 144 | lua_settop(L, 1); | 143 | lua_settop(L, 1); |
| 145 | if (lua_isnil(L, 1)) | 144 | if (lua_isnil(L, 1)) |
| @@ -147,7 +146,7 @@ static void sethook (lua_State *L, const l_char *key, lua_Hook hook, | |||
| 147 | else if (lua_isfunction(L, 1)) | 146 | else if (lua_isfunction(L, 1)) |
| 148 | (*sethookf)(L, hook); | 147 | (*sethookf)(L, hook); |
| 149 | else | 148 | else |
| 150 | luaL_argerror(L, 1, l_s("function expected")); | 149 | luaL_argerror(L, 1, "function expected"); |
| 151 | lua_pushstring(L, key); | 150 | lua_pushstring(L, key); |
| 152 | lua_gettable(L, LUA_REGISTRYINDEX); /* get old value */ | 151 | lua_gettable(L, LUA_REGISTRYINDEX); /* get old value */ |
| 153 | lua_pushstring(L, key); | 152 | lua_pushstring(L, key); |
| @@ -169,11 +168,11 @@ static int setlinehook (lua_State *L) { | |||
| 169 | 168 | ||
| 170 | 169 | ||
| 171 | static const luaL_reg dblib[] = { | 170 | static const luaL_reg dblib[] = { |
| 172 | {l_s("getlocal"), getlocal}, | 171 | {"getlocal", getlocal}, |
| 173 | {l_s("getinfo"), getinfo}, | 172 | {"getinfo", getinfo}, |
| 174 | {l_s("setcallhook"), setcallhook}, | 173 | {"setcallhook", setcallhook}, |
| 175 | {l_s("setlinehook"), setlinehook}, | 174 | {"setlinehook", setlinehook}, |
| 176 | {l_s("setlocal"), setlocal} | 175 | {"setlocal", setlocal} |
| 177 | }; | 176 | }; |
| 178 | 177 | ||
| 179 | 178 | ||
