diff options
| -rw-r--r-- | ltests.c | 40 |
1 files changed, 35 insertions, 5 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 2.68 2009/07/15 18:37:19 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.69 2009/08/26 17:41:26 roberto Exp roberto $ |
| 3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -813,7 +813,13 @@ static int int2fb_aux (lua_State *L) { | |||
| 813 | static const char *const delimits = " \t\n,;"; | 813 | static const char *const delimits = " \t\n,;"; |
| 814 | 814 | ||
| 815 | static void skip (const char **pc) { | 815 | static void skip (const char **pc) { |
| 816 | while (**pc != '\0' && strchr(delimits, **pc)) (*pc)++; | 816 | for (;;) { |
| 817 | if (**pc != '\0' && strchr(delimits, **pc)) (*pc)++; | ||
| 818 | else if (**pc == '#') { | ||
| 819 | while (**pc != '\n' && **pc != '\0') (*pc)++; | ||
| 820 | } | ||
| 821 | else break; | ||
| 822 | } | ||
| 817 | } | 823 | } |
| 818 | 824 | ||
| 819 | static int getnum_aux (lua_State *L, const char **pc) { | 825 | static int getnum_aux (lua_State *L, const char **pc) { |
| @@ -950,6 +956,9 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { | |||
| 950 | else if EQ("pushcclosure") { | 956 | else if EQ("pushcclosure") { |
| 951 | lua_pushcclosure(L1, testC, getnum); | 957 | lua_pushcclosure(L1, testC, getnum); |
| 952 | } | 958 | } |
| 959 | else if EQ("pushupvalueindex") { | ||
| 960 | lua_pushinteger(L1, lua_upvalueindex(getnum)); | ||
| 961 | } | ||
| 953 | else if EQ("remove") { | 962 | else if EQ("remove") { |
| 954 | lua_remove(L1, getnum); | 963 | lua_remove(L1, getnum); |
| 955 | } | 964 | } |
| @@ -972,7 +981,20 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { | |||
| 972 | lua_concat(L1, getnum); | 981 | lua_concat(L1, getnum); |
| 973 | } | 982 | } |
| 974 | else if EQ("print") { | 983 | else if EQ("print") { |
| 975 | printf("%s\n", lua_tostring(L1, getnum)); | 984 | int n = getnum; |
| 985 | if (n != 0) { | ||
| 986 | printf("%s\n", luaL_tolstring(L1, n, NULL)); | ||
| 987 | lua_pop(L1, 1); | ||
| 988 | } | ||
| 989 | else { | ||
| 990 | int i; | ||
| 991 | n = lua_gettop(L1); | ||
| 992 | for (i = 1; i <= n; i++) { | ||
| 993 | printf("%s ", luaL_tolstring(L1, i, NULL)); | ||
| 994 | lua_pop(L1, 1); | ||
| 995 | } | ||
| 996 | printf("\n"); | ||
| 997 | } | ||
| 976 | } | 998 | } |
| 977 | else if EQ("arith") { | 999 | else if EQ("arith") { |
| 978 | static char ops[] = "+-*/%^_"; | 1000 | static char ops[] = "+-*/%^_"; |
| @@ -1002,6 +1024,15 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { | |||
| 1002 | int i = getnum; | 1024 | int i = getnum; |
| 1003 | lua_pcallk(L1, narg, nres, 0, i, Cfunck); | 1025 | lua_pcallk(L1, narg, nres, 0, i, Cfunck); |
| 1004 | } | 1026 | } |
| 1027 | else if EQ("callk") { | ||
| 1028 | int narg = getnum; | ||
| 1029 | int nres = getnum; | ||
| 1030 | int i = getnum; | ||
| 1031 | lua_callk(L1, narg, nres, i, Cfunck); | ||
| 1032 | } | ||
| 1033 | else if EQ("yield") { | ||
| 1034 | return lua_yield(L1, getnum); | ||
| 1035 | } | ||
| 1005 | else if EQ("loadstring") { | 1036 | else if EQ("loadstring") { |
| 1006 | size_t sl; | 1037 | size_t sl; |
| 1007 | const char *s = luaL_checklstring(L1, getnum, &sl); | 1038 | const char *s = luaL_checklstring(L1, getnum, &sl); |
| @@ -1095,8 +1126,7 @@ static int Cfunck (lua_State *L) { | |||
| 1095 | 1126 | ||
| 1096 | static int makeCfunc (lua_State *L) { | 1127 | static int makeCfunc (lua_State *L) { |
| 1097 | luaL_checkstring(L, 1); | 1128 | luaL_checkstring(L, 1); |
| 1098 | lua_settop(L, 1); | 1129 | lua_pushcclosure(L, Cfunc, lua_gettop(L)); |
| 1099 | lua_pushcclosure(L, Cfunc, 1); | ||
| 1100 | return 1; | 1130 | return 1; |
| 1101 | } | 1131 | } |
| 1102 | 1132 | ||
