diff options
Diffstat (limited to 'ltests.c')
-rw-r--r-- | ltests.c | 86 |
1 files changed, 43 insertions, 43 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.17 2005/01/14 14:19:42 roberto Exp $ | 2 | ** $Id: ltests.c,v 2.19 2005/01/19 15:54: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 | */ |
@@ -249,6 +249,7 @@ static void checkproto (global_State *g, Proto *f) { | |||
249 | 249 | ||
250 | static void checkclosure (global_State *g, Closure *cl) { | 250 | static void checkclosure (global_State *g, Closure *cl) { |
251 | GCObject *clgc = obj2gco(cl); | 251 | GCObject *clgc = obj2gco(cl); |
252 | checkobjref(g, clgc, cl->l.env); | ||
252 | if (cl->c.isC) { | 253 | if (cl->c.isC) { |
253 | int i; | 254 | int i; |
254 | for (i=0; i<cl->c.nupvalues; i++) | 255 | for (i=0; i<cl->c.nupvalues; i++) |
@@ -257,7 +258,6 @@ static void checkclosure (global_State *g, Closure *cl) { | |||
257 | else { | 258 | else { |
258 | int i; | 259 | int i; |
259 | lua_assert(cl->l.nupvalues == cl->l.p->nups); | 260 | lua_assert(cl->l.nupvalues == cl->l.p->nups); |
260 | checkobjref(g, clgc, hvalue(&cl->l.g)); | ||
261 | checkobjref(g, clgc, cl->l.p); | 261 | checkobjref(g, clgc, cl->l.p); |
262 | for (i=0; i<cl->l.nupvalues; i++) { | 262 | for (i=0; i<cl->l.nupvalues; i++) { |
263 | if (cl->l.upvals[i]) { | 263 | if (cl->l.upvals[i]) { |
@@ -622,20 +622,6 @@ static int unref (lua_State *L) { | |||
622 | return 0; | 622 | return 0; |
623 | } | 623 | } |
624 | 624 | ||
625 | static int metatable (lua_State *L) { | ||
626 | luaL_checkany(L, 1); | ||
627 | if (lua_isnone(L, 2)) { | ||
628 | if (lua_getmetatable(L, 1) == 0) | ||
629 | lua_pushnil(L); | ||
630 | } | ||
631 | else { | ||
632 | lua_settop(L, 2); | ||
633 | luaL_checktype(L, 2, LUA_TTABLE); | ||
634 | lua_setmetatable(L, 1); | ||
635 | } | ||
636 | return 1; | ||
637 | } | ||
638 | |||
639 | 625 | ||
640 | static int upvalue (lua_State *L) { | 626 | static int upvalue (lua_State *L) { |
641 | int n = luaL_checkint(L, 2); | 627 | int n = luaL_checkint(L, 2); |
@@ -814,10 +800,22 @@ static const char *getname_aux (char *buff, const char **pc) { | |||
814 | } | 800 | } |
815 | 801 | ||
816 | 802 | ||
803 | static int getindex_aux (lua_State *L, const char **pc) { | ||
804 | skip(pc); | ||
805 | switch (*(*pc)++) { | ||
806 | case 'R': return LUA_REGISTRYINDEX; | ||
807 | case 'G': return LUA_GLOBALSINDEX; | ||
808 | case 'E': return LUA_ENVIRONINDEX; | ||
809 | case 'U': return lua_upvalueindex(getnum_aux(L, pc)); | ||
810 | default: (*pc)--; return getnum_aux(L, pc); | ||
811 | } | ||
812 | } | ||
813 | |||
817 | #define EQ(s1) (strcmp(s1, inst) == 0) | 814 | #define EQ(s1) (strcmp(s1, inst) == 0) |
818 | 815 | ||
819 | #define getnum (getnum_aux(L, &pc)) | 816 | #define getnum (getnum_aux(L, &pc)) |
820 | #define getname (getname_aux(buff, &pc)) | 817 | #define getname (getname_aux(buff, &pc)) |
818 | #define getindex (getindex_aux(L, &pc)) | ||
821 | 819 | ||
822 | 820 | ||
823 | static int testC (lua_State *L) { | 821 | static int testC (lua_State *L) { |
@@ -836,44 +834,44 @@ static int testC (lua_State *L) { | |||
836 | const char *inst = getname; | 834 | const char *inst = getname; |
837 | if EQ("") return 0; | 835 | if EQ("") return 0; |
838 | else if EQ("isnumber") { | 836 | else if EQ("isnumber") { |
839 | lua_pushinteger(L1, lua_isnumber(L1, getnum)); | 837 | lua_pushinteger(L1, lua_isnumber(L1, getindex)); |
840 | } | 838 | } |
841 | else if EQ("isstring") { | 839 | else if EQ("isstring") { |
842 | lua_pushinteger(L1, lua_isstring(L1, getnum)); | 840 | lua_pushinteger(L1, lua_isstring(L1, getindex)); |
843 | } | 841 | } |
844 | else if EQ("istable") { | 842 | else if EQ("istable") { |
845 | lua_pushinteger(L1, lua_istable(L1, getnum)); | 843 | lua_pushinteger(L1, lua_istable(L1, getindex)); |
846 | } | 844 | } |
847 | else if EQ("iscfunction") { | 845 | else if EQ("iscfunction") { |
848 | lua_pushinteger(L1, lua_iscfunction(L1, getnum)); | 846 | lua_pushinteger(L1, lua_iscfunction(L1, getindex)); |
849 | } | 847 | } |
850 | else if EQ("isfunction") { | 848 | else if EQ("isfunction") { |
851 | lua_pushinteger(L1, lua_isfunction(L1, getnum)); | 849 | lua_pushinteger(L1, lua_isfunction(L1, getindex)); |
852 | } | 850 | } |
853 | else if EQ("isuserdata") { | 851 | else if EQ("isuserdata") { |
854 | lua_pushinteger(L1, lua_isuserdata(L1, getnum)); | 852 | lua_pushinteger(L1, lua_isuserdata(L1, getindex)); |
855 | } | 853 | } |
856 | else if EQ("isudataval") { | 854 | else if EQ("isudataval") { |
857 | lua_pushinteger(L1, lua_islightuserdata(L1, getnum)); | 855 | lua_pushinteger(L1, lua_islightuserdata(L1, getindex)); |
858 | } | 856 | } |
859 | else if EQ("isnil") { | 857 | else if EQ("isnil") { |
860 | lua_pushinteger(L1, lua_isnil(L1, getnum)); | 858 | lua_pushinteger(L1, lua_isnil(L1, getindex)); |
861 | } | 859 | } |
862 | else if EQ("isnull") { | 860 | else if EQ("isnull") { |
863 | lua_pushinteger(L1, lua_isnone(L1, getnum)); | 861 | lua_pushinteger(L1, lua_isnone(L1, getindex)); |
864 | } | 862 | } |
865 | else if EQ("tonumber") { | 863 | else if EQ("tonumber") { |
866 | lua_pushnumber(L1, lua_tonumber(L1, getnum)); | 864 | lua_pushnumber(L1, lua_tonumber(L1, getindex)); |
867 | } | 865 | } |
868 | else if EQ("tostring") { | 866 | else if EQ("tostring") { |
869 | const char *s = lua_tostring(L1, getnum); | 867 | const char *s = lua_tostring(L1, getindex); |
870 | lua_pushstring(L1, s); | 868 | lua_pushstring(L1, s); |
871 | } | 869 | } |
872 | else if EQ("objsize") { | 870 | else if EQ("objsize") { |
873 | lua_pushinteger(L1, lua_objsize(L1, getnum)); | 871 | lua_pushinteger(L1, lua_objsize(L1, getindex)); |
874 | } | 872 | } |
875 | else if EQ("tocfunction") { | 873 | else if EQ("tocfunction") { |
876 | lua_pushcfunction(L1, lua_tocfunction(L1, getnum)); | 874 | lua_pushcfunction(L1, lua_tocfunction(L1, getindex)); |
877 | } | 875 | } |
878 | else if EQ("return") { | 876 | else if EQ("return") { |
879 | return getnum; | 877 | return getnum; |
@@ -899,11 +897,14 @@ static int testC (lua_State *L) { | |||
899 | else if EQ("pushbool") { | 897 | else if EQ("pushbool") { |
900 | lua_pushboolean(L1, getnum); | 898 | lua_pushboolean(L1, getnum); |
901 | } | 899 | } |
900 | else if EQ("newuserdata") { | ||
901 | lua_newuserdata(L1, getnum); | ||
902 | } | ||
902 | else if EQ("tobool") { | 903 | else if EQ("tobool") { |
903 | lua_pushinteger(L1, lua_toboolean(L1, getnum)); | 904 | lua_pushinteger(L1, lua_toboolean(L1, getindex)); |
904 | } | 905 | } |
905 | else if EQ("pushvalue") { | 906 | else if EQ("pushvalue") { |
906 | lua_pushvalue(L1, getnum); | 907 | lua_pushvalue(L1, getindex); |
907 | } | 908 | } |
908 | else if EQ("pushcclosure") { | 909 | else if EQ("pushcclosure") { |
909 | lua_pushcclosure(L1, testC, getnum); | 910 | lua_pushcclosure(L1, testC, getnum); |
@@ -915,13 +916,13 @@ static int testC (lua_State *L) { | |||
915 | lua_insert(L1, getnum); | 916 | lua_insert(L1, getnum); |
916 | } | 917 | } |
917 | else if EQ("replace") { | 918 | else if EQ("replace") { |
918 | lua_replace(L1, getnum); | 919 | lua_replace(L1, getindex); |
919 | } | 920 | } |
920 | else if EQ("gettable") { | 921 | else if EQ("gettable") { |
921 | lua_gettable(L1, getnum); | 922 | lua_gettable(L1, getindex); |
922 | } | 923 | } |
923 | else if EQ("settable") { | 924 | else if EQ("settable") { |
924 | lua_settable(L1, getnum); | 925 | lua_settable(L1, getindex); |
925 | } | 926 | } |
926 | else if EQ("next") { | 927 | else if EQ("next") { |
927 | lua_next(L1, -2); | 928 | lua_next(L1, -2); |
@@ -930,12 +931,12 @@ static int testC (lua_State *L) { | |||
930 | lua_concat(L1, getnum); | 931 | lua_concat(L1, getnum); |
931 | } | 932 | } |
932 | else if EQ("lessthan") { | 933 | else if EQ("lessthan") { |
933 | int a = getnum; | 934 | int a = getindex; |
934 | lua_pushboolean(L1, lua_lessthan(L1, a, getnum)); | 935 | lua_pushboolean(L1, lua_lessthan(L1, a, getindex)); |
935 | } | 936 | } |
936 | else if EQ("equal") { | 937 | else if EQ("equal") { |
937 | int a = getnum; | 938 | int a = getindex; |
938 | lua_pushboolean(L1, lua_equal(L1, a, getnum)); | 939 | lua_pushboolean(L1, lua_equal(L1, a, getindex)); |
939 | } | 940 | } |
940 | else if EQ("rawcall") { | 941 | else if EQ("rawcall") { |
941 | int narg = getnum; | 942 | int narg = getnum; |
@@ -956,21 +957,21 @@ static int testC (lua_State *L) { | |||
956 | luaL_loadfile(L1, luaL_checkstring(L1, getnum)); | 957 | luaL_loadfile(L1, luaL_checkstring(L1, getnum)); |
957 | } | 958 | } |
958 | else if EQ("setmetatable") { | 959 | else if EQ("setmetatable") { |
959 | lua_setmetatable(L1, getnum); | 960 | lua_setmetatable(L1, getindex); |
960 | } | 961 | } |
961 | else if EQ("getmetatable") { | 962 | else if EQ("getmetatable") { |
962 | if (lua_getmetatable(L1, getnum) == 0) | 963 | if (lua_getmetatable(L1, getindex) == 0) |
963 | lua_pushnil(L1); | 964 | lua_pushnil(L1); |
964 | } | 965 | } |
965 | else if EQ("type") { | 966 | else if EQ("type") { |
966 | lua_pushstring(L1, luaL_typename(L1, getnum)); | 967 | lua_pushstring(L1, luaL_typename(L1, getnum)); |
967 | } | 968 | } |
968 | else if EQ("getn") { | 969 | else if EQ("getn") { |
969 | int i = getnum; | 970 | int i = getindex; |
970 | lua_pushinteger(L1, luaL_getn(L1, i)); | 971 | lua_pushinteger(L1, luaL_getn(L1, i)); |
971 | } | 972 | } |
972 | else if EQ("setn") { | 973 | else if EQ("setn") { |
973 | int i = getnum; | 974 | int i = getindex; |
974 | int n = cast(int, lua_tonumber(L1, -1)); | 975 | int n = cast(int, lua_tonumber(L1, -1)); |
975 | luaL_setn(L1, i, n); | 976 | luaL_setn(L1, i, n); |
976 | lua_pop(L1, 1); | 977 | lua_pop(L1, 1); |
@@ -1095,7 +1096,6 @@ static const struct luaL_reg tests_funcs[] = { | |||
1095 | {"unref", unref}, | 1096 | {"unref", unref}, |
1096 | {"d2s", d2s}, | 1097 | {"d2s", d2s}, |
1097 | {"s2d", s2d}, | 1098 | {"s2d", s2d}, |
1098 | {"metatable", metatable}, | ||
1099 | {"upvalue", upvalue}, | 1099 | {"upvalue", upvalue}, |
1100 | {"newuserdata", newuserdata}, | 1100 | {"newuserdata", newuserdata}, |
1101 | {"pushuserdata", pushuserdata}, | 1101 | {"pushuserdata", pushuserdata}, |