diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-04-14 16:10:17 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-04-14 16:10:17 -0300 |
| commit | 8775f25830df02bc736296f70573032fa7781761 (patch) | |
| tree | 41715e9d30274d831423ba7741ec454c8cc53612 | |
| parent | 70a63fa5adfb2480ce385502f1d0306000217690 (diff) | |
| download | lua-8775f25830df02bc736296f70573032fa7781761.tar.gz lua-8775f25830df02bc736296f70573032fa7781761.tar.bz2 lua-8775f25830df02bc736296f70573032fa7781761.zip | |
new function 'T.makeCfunc' (for later use)
| -rw-r--r-- | ltests.c | 54 |
1 files changed, 38 insertions, 16 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 2.58 2009/02/19 17:18:25 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.59 2009/03/03 18:52:36 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 | */ |
| @@ -867,22 +867,10 @@ static int getindex_aux (lua_State *L, const char **pc) { | |||
| 867 | #define getindex (getindex_aux(L, &pc)) | 867 | #define getindex (getindex_aux(L, &pc)) |
| 868 | 868 | ||
| 869 | 869 | ||
| 870 | static int testC (lua_State *L) { | 870 | static int testC (lua_State *L); |
| 871 | |||
| 872 | static int runC (lua_State *L, lua_State *L1, const char *pc) { | ||
| 871 | char buff[30]; | 873 | char buff[30]; |
| 872 | lua_State *L1; | ||
| 873 | const char *pc; | ||
| 874 | if (lua_isuserdata(L, 1)) { | ||
| 875 | L1 = getstate(L); | ||
| 876 | pc = luaL_checkstring(L, 2); | ||
| 877 | } | ||
| 878 | else if (lua_isthread(L, 1)) { | ||
| 879 | L1 = lua_tothread(L, 1); | ||
| 880 | pc = luaL_checkstring(L, 2); | ||
| 881 | } | ||
| 882 | else { | ||
| 883 | L1 = L; | ||
| 884 | pc = luaL_checkstring(L, 1); | ||
| 885 | } | ||
| 886 | for (;;) { | 874 | for (;;) { |
| 887 | const char *inst = getname; | 875 | const char *inst = getname; |
| 888 | if EQ("") return 0; | 876 | if EQ("") return 0; |
| @@ -1058,6 +1046,39 @@ static struct X { int x; } x; | |||
| 1058 | return 0; | 1046 | return 0; |
| 1059 | } | 1047 | } |
| 1060 | 1048 | ||
| 1049 | |||
| 1050 | static int testC (lua_State *L) { | ||
| 1051 | lua_State *L1; | ||
| 1052 | const char *pc; | ||
| 1053 | if (lua_isuserdata(L, 1)) { | ||
| 1054 | L1 = getstate(L); | ||
| 1055 | pc = luaL_checkstring(L, 2); | ||
| 1056 | } | ||
| 1057 | else if (lua_isthread(L, 1)) { | ||
| 1058 | L1 = lua_tothread(L, 1); | ||
| 1059 | pc = luaL_checkstring(L, 2); | ||
| 1060 | } | ||
| 1061 | else { | ||
| 1062 | L1 = L; | ||
| 1063 | pc = luaL_checkstring(L, 1); | ||
| 1064 | } | ||
| 1065 | return runC(L, L1, pc); | ||
| 1066 | } | ||
| 1067 | |||
| 1068 | |||
| 1069 | static int Cfunc (lua_State *L) { | ||
| 1070 | return runC(L, L, lua_tostring(L, lua_upvalueindex(1))); | ||
| 1071 | } | ||
| 1072 | |||
| 1073 | |||
| 1074 | static int makeCfunc (lua_State *L) { | ||
| 1075 | luaL_checkstring(L, 1); | ||
| 1076 | lua_settop(L, 1); | ||
| 1077 | lua_pushcclosure(L, Cfunc, 1); | ||
| 1078 | return 1; | ||
| 1079 | } | ||
| 1080 | |||
| 1081 | |||
| 1061 | /* }====================================================== */ | 1082 | /* }====================================================== */ |
| 1062 | 1083 | ||
| 1063 | 1084 | ||
| @@ -1135,6 +1156,7 @@ static const struct luaL_Reg tests_funcs[] = { | |||
| 1135 | {"setyhook", setyhook}, | 1156 | {"setyhook", setyhook}, |
| 1136 | {"stacklevel", stacklevel}, | 1157 | {"stacklevel", stacklevel}, |
| 1137 | {"testC", testC}, | 1158 | {"testC", testC}, |
| 1159 | {"makeCfunc", makeCfunc}, | ||
| 1138 | {"totalmem", mem_query}, | 1160 | {"totalmem", mem_query}, |
| 1139 | {"trick", settrick}, | 1161 | {"trick", settrick}, |
| 1140 | {"udataval", udataval}, | 1162 | {"udataval", udataval}, |
