diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-08-26 14:41:26 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-08-26 14:41:26 -0300 |
commit | b2bb2f7f592c0dfaa3a2aa523a97597d49c2252c (patch) | |
tree | c5885dc650b498c1962c36d1ad3dc1732ddf8d81 /ltests.c | |
parent | f096ab5421e09acf3cb70661862b69fa100bff80 (diff) | |
download | lua-b2bb2f7f592c0dfaa3a2aa523a97597d49c2252c.tar.gz lua-b2bb2f7f592c0dfaa3a2aa523a97597d49c2252c.tar.bz2 lua-b2bb2f7f592c0dfaa3a2aa523a97597d49c2252c.zip |
better machinery to test continuations in the C API
Diffstat (limited to 'ltests.c')
-rw-r--r-- | ltests.c | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.67 2009/07/15 17:26:14 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.68 2009/07/15 18:37:19 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 | */ |
@@ -863,6 +863,7 @@ static int getindex_aux (lua_State *L, const char **pc) { | |||
863 | 863 | ||
864 | 864 | ||
865 | static int testC (lua_State *L); | 865 | static int testC (lua_State *L); |
866 | static int Cfunck (lua_State *L); | ||
866 | 867 | ||
867 | static int runC (lua_State *L, lua_State *L1, const char *pc) { | 868 | static int runC (lua_State *L, lua_State *L1, const char *pc) { |
868 | char buff[30]; | 869 | char buff[30]; |
@@ -970,6 +971,9 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { | |||
970 | else if EQ("concat") { | 971 | else if EQ("concat") { |
971 | lua_concat(L1, getnum); | 972 | lua_concat(L1, getnum); |
972 | } | 973 | } |
974 | else if EQ("print") { | ||
975 | printf("%s\n", lua_tostring(L1, getnum)); | ||
976 | } | ||
973 | else if EQ("arith") { | 977 | else if EQ("arith") { |
974 | static char ops[] = "+-*/%^_"; | 978 | static char ops[] = "+-*/%^_"; |
975 | int op; | 979 | int op; |
@@ -992,6 +996,12 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { | |||
992 | int nres = getnum; | 996 | int nres = getnum; |
993 | lua_pcall(L1, narg, nres, 0); | 997 | lua_pcall(L1, narg, nres, 0); |
994 | } | 998 | } |
999 | else if EQ("pcallk") { | ||
1000 | int narg = getnum; | ||
1001 | int nres = getnum; | ||
1002 | int i = getnum; | ||
1003 | lua_pcallk(L1, narg, nres, 0, i, Cfunck); | ||
1004 | } | ||
995 | else if EQ("loadstring") { | 1005 | else if EQ("loadstring") { |
996 | size_t sl; | 1006 | size_t sl; |
997 | const char *s = luaL_checklstring(L1, getnum, &sl); | 1007 | const char *s = luaL_checklstring(L1, getnum, &sl); |
@@ -1014,6 +1024,12 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { | |||
1014 | int i = getindex; | 1024 | int i = getindex; |
1015 | lua_pushinteger(L1, lua_objlen(L1, i)); | 1025 | lua_pushinteger(L1, lua_objlen(L1, i)); |
1016 | } | 1026 | } |
1027 | else if EQ("getctx") { | ||
1028 | int i = 0; | ||
1029 | int s = lua_getctx(L1, &i); | ||
1030 | lua_pushinteger(L1, s); | ||
1031 | lua_pushinteger(L1, i); | ||
1032 | } | ||
1017 | else if EQ("checkstack") { | 1033 | else if EQ("checkstack") { |
1018 | if (!lua_checkstack(L1, getnum)) | 1034 | if (!lua_checkstack(L1, getnum)) |
1019 | luaL_error(L, "C stack overflow"); | 1035 | luaL_error(L, "C stack overflow"); |
@@ -1070,6 +1086,13 @@ static int Cfunc (lua_State *L) { | |||
1070 | } | 1086 | } |
1071 | 1087 | ||
1072 | 1088 | ||
1089 | static int Cfunck (lua_State *L) { | ||
1090 | int i = 0; | ||
1091 | lua_getctx(L, &i); | ||
1092 | return runC(L, L, lua_tostring(L, i)); | ||
1093 | } | ||
1094 | |||
1095 | |||
1073 | static int makeCfunc (lua_State *L) { | 1096 | static int makeCfunc (lua_State *L) { |
1074 | luaL_checkstring(L, 1); | 1097 | luaL_checkstring(L, 1); |
1075 | lua_settop(L, 1); | 1098 | lua_settop(L, 1); |