summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-06-02 16:08:52 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-06-02 16:08:52 -0300
commitfa38421cea9f92e643e7598fa5ea6f6efc3e53ee (patch)
treea60809a76778789cd31979c7ceffb1e65856f1ce
parente8d4fe72366dd44e45ffd9fca09d92c3db4f8214 (diff)
downloadlua-fa38421cea9f92e643e7598fa5ea6f6efc3e53ee.tar.gz
lua-fa38421cea9f92e643e7598fa5ea6f6efc3e53ee.tar.bz2
lua-fa38421cea9f92e643e7598fa5ea6f6efc3e53ee.zip
`testC' can operate on other states
-rw-r--r--ltests.c117
1 files changed, 64 insertions, 53 deletions
diff --git a/ltests.c b/ltests.c
index afdfb515..8b9226ae 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 2.7 2004/05/31 18:50:48 roberto Exp roberto $ 2** $Id: ltests.c,v 2.8 2004/05/31 19:41:52 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*/
@@ -687,11 +687,11 @@ static int d2s (lua_State *L) {
687 687
688 688
689static int newstate (lua_State *L) { 689static int newstate (lua_State *L) {
690 lua_State *L1 = lua_newstate(debug_realloc, &memcontrol); 690 void *ud;
691 if (L1) { 691 lua_Alloc f = lua_getallocf(L, &ud);
692 lua_userstateopen(L1); /* init lock */ 692 lua_State *L1 = lua_newstate(f, ud);
693 if (L1)
693 lua_pushinteger(L, (unsigned long)L1); 694 lua_pushinteger(L, (unsigned long)L1);
694 }
695 else 695 else
696 lua_pushnil(L); 696 lua_pushnil(L);
697 return 1; 697 return 1;
@@ -810,153 +810,165 @@ static const char *getname_aux (char *buff, const char **pc) {
810 810
811static int testC (lua_State *L) { 811static int testC (lua_State *L) {
812 char buff[30]; 812 char buff[30];
813 const char *pc = luaL_checkstring(L, 1); 813 lua_State *L1;
814 const char *pc;
815 if (lua_isnumber(L, 1)) {
816 L1 = cast(lua_State *,cast(unsigned long,luaL_checknumber(L, 1)));
817 pc = luaL_checkstring(L, 2);
818 }
819 else {
820 L1 = L;
821 pc = luaL_checkstring(L, 1);
822 }
814 for (;;) { 823 for (;;) {
815 const char *inst = getname; 824 const char *inst = getname;
816 if EQ("") return 0; 825 if EQ("") return 0;
817 else if EQ("isnumber") { 826 else if EQ("isnumber") {
818 lua_pushinteger(L, lua_isnumber(L, getnum)); 827 lua_pushinteger(L1, lua_isnumber(L1, getnum));
819 } 828 }
820 else if EQ("isstring") { 829 else if EQ("isstring") {
821 lua_pushinteger(L, lua_isstring(L, getnum)); 830 lua_pushinteger(L1, lua_isstring(L1, getnum));
822 } 831 }
823 else if EQ("istable") { 832 else if EQ("istable") {
824 lua_pushinteger(L, lua_istable(L, getnum)); 833 lua_pushinteger(L1, lua_istable(L1, getnum));
825 } 834 }
826 else if EQ("iscfunction") { 835 else if EQ("iscfunction") {
827 lua_pushinteger(L, lua_iscfunction(L, getnum)); 836 lua_pushinteger(L1, lua_iscfunction(L1, getnum));
828 } 837 }
829 else if EQ("isfunction") { 838 else if EQ("isfunction") {
830 lua_pushinteger(L, lua_isfunction(L, getnum)); 839 lua_pushinteger(L1, lua_isfunction(L1, getnum));
831 } 840 }
832 else if EQ("isuserdata") { 841 else if EQ("isuserdata") {
833 lua_pushinteger(L, lua_isuserdata(L, getnum)); 842 lua_pushinteger(L1, lua_isuserdata(L1, getnum));
834 } 843 }
835 else if EQ("isudataval") { 844 else if EQ("isudataval") {
836 lua_pushinteger(L, lua_islightuserdata(L, getnum)); 845 lua_pushinteger(L1, lua_islightuserdata(L1, getnum));
837 } 846 }
838 else if EQ("isnil") { 847 else if EQ("isnil") {
839 lua_pushinteger(L, lua_isnil(L, getnum)); 848 lua_pushinteger(L1, lua_isnil(L1, getnum));
840 } 849 }
841 else if EQ("isnull") { 850 else if EQ("isnull") {
842 lua_pushinteger(L, lua_isnone(L, getnum)); 851 lua_pushinteger(L1, lua_isnone(L1, getnum));
843 } 852 }
844 else if EQ("tonumber") { 853 else if EQ("tonumber") {
845 lua_pushnumber(L, lua_tonumber(L, getnum)); 854 lua_pushnumber(L1, lua_tonumber(L1, getnum));
846 } 855 }
847 else if EQ("tostring") { 856 else if EQ("tostring") {
848 const char *s = lua_tostring(L, getnum); 857 const char *s = lua_tostring(L1, getnum);
849 lua_pushstring(L, s); 858 lua_pushstring(L1, s);
850 } 859 }
851 else if EQ("objsize") { 860 else if EQ("objsize") {
852 lua_pushinteger(L, lua_objsize(L, getnum)); 861 lua_pushinteger(L1, lua_objsize(L1, getnum));
853 } 862 }
854 else if EQ("tocfunction") { 863 else if EQ("tocfunction") {
855 lua_pushcfunction(L, lua_tocfunction(L, getnum)); 864 lua_pushcfunction(L1, lua_tocfunction(L1, getnum));
856 } 865 }
857 else if EQ("return") { 866 else if EQ("return") {
858 return getnum; 867 return getnum;
859 } 868 }
860 else if EQ("gettop") { 869 else if EQ("gettop") {
861 lua_pushinteger(L, lua_gettop(L)); 870 lua_pushinteger(L1, lua_gettop(L1));
862 } 871 }
863 else if EQ("settop") { 872 else if EQ("settop") {
864 lua_settop(L, getnum); 873 lua_settop(L1, getnum);
865 } 874 }
866 else if EQ("pop") { 875 else if EQ("pop") {
867 lua_pop(L, getnum); 876 lua_pop(L1, getnum);
868 } 877 }
869 else if EQ("pushnum") { 878 else if EQ("pushnum") {
870 lua_pushinteger(L, getnum); 879 lua_pushinteger(L1, getnum);
880 }
881 else if EQ("pushstring") {
882 lua_pushstring(L1, getname);
871 } 883 }
872 else if EQ("pushnil") { 884 else if EQ("pushnil") {
873 lua_pushnil(L); 885 lua_pushnil(L1);
874 } 886 }
875 else if EQ("pushbool") { 887 else if EQ("pushbool") {
876 lua_pushboolean(L, getnum); 888 lua_pushboolean(L1, getnum);
877 } 889 }
878 else if EQ("tobool") { 890 else if EQ("tobool") {
879 lua_pushinteger(L, lua_toboolean(L, getnum)); 891 lua_pushinteger(L1, lua_toboolean(L1, getnum));
880 } 892 }
881 else if EQ("pushvalue") { 893 else if EQ("pushvalue") {
882 lua_pushvalue(L, getnum); 894 lua_pushvalue(L1, getnum);
883 } 895 }
884 else if EQ("pushcclosure") { 896 else if EQ("pushcclosure") {
885 lua_pushcclosure(L, testC, getnum); 897 lua_pushcclosure(L1, testC, getnum);
886 } 898 }
887 else if EQ("remove") { 899 else if EQ("remove") {
888 lua_remove(L, getnum); 900 lua_remove(L1, getnum);
889 } 901 }
890 else if EQ("insert") { 902 else if EQ("insert") {
891 lua_insert(L, getnum); 903 lua_insert(L1, getnum);
892 } 904 }
893 else if EQ("replace") { 905 else if EQ("replace") {
894 lua_replace(L, getnum); 906 lua_replace(L1, getnum);
895 } 907 }
896 else if EQ("gettable") { 908 else if EQ("gettable") {
897 lua_gettable(L, getnum); 909 lua_gettable(L1, getnum);
898 } 910 }
899 else if EQ("settable") { 911 else if EQ("settable") {
900 lua_settable(L, getnum); 912 lua_settable(L1, getnum);
901 } 913 }
902 else if EQ("next") { 914 else if EQ("next") {
903 lua_next(L, -2); 915 lua_next(L1, -2);
904 } 916 }
905 else if EQ("concat") { 917 else if EQ("concat") {
906 lua_concat(L, getnum); 918 lua_concat(L1, getnum);
907 } 919 }
908 else if EQ("lessthan") { 920 else if EQ("lessthan") {
909 int a = getnum; 921 int a = getnum;
910 lua_pushboolean(L, lua_lessthan(L, a, getnum)); 922 lua_pushboolean(L1, lua_lessthan(L1, a, getnum));
911 } 923 }
912 else if EQ("equal") { 924 else if EQ("equal") {
913 int a = getnum; 925 int a = getnum;
914 lua_pushboolean(L, lua_equal(L, a, getnum)); 926 lua_pushboolean(L1, lua_equal(L1, a, getnum));
915 } 927 }
916 else if EQ("rawcall") { 928 else if EQ("rawcall") {
917 int narg = getnum; 929 int narg = getnum;
918 int nres = getnum; 930 int nres = getnum;
919 lua_call(L, narg, nres); 931 lua_call(L1, narg, nres);
920 } 932 }
921 else if EQ("call") { 933 else if EQ("call") {
922 int narg = getnum; 934 int narg = getnum;
923 int nres = getnum; 935 int nres = getnum;
924 lua_pcall(L, narg, nres, 0); 936 lua_pcall(L1, narg, nres, 0);
925 } 937 }
926 else if EQ("loadstring") { 938 else if EQ("loadstring") {
927 size_t sl; 939 size_t sl;
928 const char *s = luaL_checklstring(L, getnum, &sl); 940 const char *s = luaL_checklstring(L1, getnum, &sl);
929 luaL_loadbuffer(L, s, sl, s); 941 luaL_loadbuffer(L1, s, sl, s);
930 } 942 }
931 else if EQ("loadfile") { 943 else if EQ("loadfile") {
932 luaL_loadfile(L, luaL_checkstring(L, getnum)); 944 luaL_loadfile(L1, luaL_checkstring(L1, getnum));
933 } 945 }
934 else if EQ("setmetatable") { 946 else if EQ("setmetatable") {
935 lua_setmetatable(L, getnum); 947 lua_setmetatable(L1, getnum);
936 } 948 }
937 else if EQ("getmetatable") { 949 else if EQ("getmetatable") {
938 if (lua_getmetatable(L, getnum) == 0) 950 if (lua_getmetatable(L1, getnum) == 0)
939 lua_pushnil(L); 951 lua_pushnil(L1);
940 } 952 }
941 else if EQ("type") { 953 else if EQ("type") {
942 lua_pushstring(L, lua_typename(L, lua_type(L, getnum))); 954 lua_pushstring(L1, lua_typename(L1, lua_type(L1, getnum)));
943 } 955 }
944 else if EQ("getn") { 956 else if EQ("getn") {
945 int i = getnum; 957 int i = getnum;
946 lua_pushinteger(L, luaL_getn(L, i)); 958 lua_pushinteger(L1, luaL_getn(L1, i));
947 } 959 }
948 else if EQ("setn") { 960 else if EQ("setn") {
949 int i = getnum; 961 int i = getnum;
950 int n = cast(int, lua_tonumber(L, -1)); 962 int n = cast(int, lua_tonumber(L1, -1));
951 luaL_setn(L, i, n); 963 luaL_setn(L1, i, n);
952 lua_pop(L, 1); 964 lua_pop(L1, 1);
953 } 965 }
954 else if EQ("throw") { 966 else if EQ("throw") {
955#ifdef __cplusplus 967#ifdef __cplusplus
956static struct X { int x; } x; 968static struct X { int x; } x;
957 throw x; 969 throw x;
958#else 970#else
959 luaL_error(L, "C++"); 971 luaL_error(L1, "C++");
960#endif 972#endif
961 break; 973 break;
962 } 974 }
@@ -1071,7 +1083,6 @@ int luaB_opentests (lua_State *L) {
1071 lua_assert(lua_getallocf(L, &ud) == debug_realloc); 1083 lua_assert(lua_getallocf(L, &ud) == debug_realloc);
1072 lua_assert(ud == cast(void *, &memcontrol)); 1084 lua_assert(ud == cast(void *, &memcontrol));
1073 lua_atpanic(L, l_panic); 1085 lua_atpanic(L, l_panic);
1074 lua_userstateopen(L); /* init lock */
1075 lua_state = L; /* keep first state to be opened */ 1086 lua_state = L; /* keep first state to be opened */
1076 luaL_openlib(L, "T", tests_funcs, 0); 1087 luaL_openlib(L, "T", tests_funcs, 0);
1077 atexit(fim); 1088 atexit(fim);