aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ltests.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/ltests.c b/ltests.c
index 5c1bc876..f2814a23 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 2.57 2009/02/18 14:52:51 roberto Exp roberto $ 2** $Id: ltests.c,v 2.58 2009/02/19 17:18:25 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*/
@@ -59,6 +59,13 @@ static void pushobject (lua_State *L, const TValue *o) {
59} 59}
60 60
61 61
62static int tpanic (lua_State *L) {
63 fprintf(stderr, "PANIC: unprotected error in call to Lua API (%s)\n",
64 lua_tostring(L, -1));
65 return (exit(EXIT_FAILURE), 0); /* do not return to Lua */
66}
67
68
62/* 69/*
63** {====================================================================== 70** {======================================================================
64** Controlled version for realloc. 71** Controlled version for realloc.
@@ -727,8 +734,10 @@ static int newstate (lua_State *L) {
727 void *ud; 734 void *ud;
728 lua_Alloc f = lua_getallocf(L, &ud); 735 lua_Alloc f = lua_getallocf(L, &ud);
729 lua_State *L1 = lua_newstate(f, ud); 736 lua_State *L1 = lua_newstate(f, ud);
730 if (L1) 737 if (L1) {
738 lua_atpanic(L1, tpanic);
731 lua_pushlightuserdata(L, L1); 739 lua_pushlightuserdata(L, L1);
740 }
732 else 741 else
733 lua_pushnil(L); 742 lua_pushnil(L);
734 return 1; 743 return 1;
@@ -866,6 +875,10 @@ static int testC (lua_State *L) {
866 L1 = getstate(L); 875 L1 = getstate(L);
867 pc = luaL_checkstring(L, 2); 876 pc = luaL_checkstring(L, 2);
868 } 877 }
878 else if (lua_isthread(L, 1)) {
879 L1 = lua_tothread(L, 1);
880 pc = luaL_checkstring(L, 2);
881 }
869 else { 882 else {
870 L1 = L; 883 L1 = L;
871 pc = luaL_checkstring(L, 1); 884 pc = luaL_checkstring(L, 1);
@@ -982,12 +995,12 @@ static int testC (lua_State *L) {
982 int a = getindex; 995 int a = getindex;
983 lua_pushboolean(L1, lua_equal(L1, a, getindex)); 996 lua_pushboolean(L1, lua_equal(L1, a, getindex));
984 } 997 }
985 else if EQ("rawcall") { 998 else if EQ("call") {
986 int narg = getnum; 999 int narg = getnum;
987 int nres = getnum; 1000 int nres = getnum;
988 lua_call(L1, narg, nres); 1001 lua_call(L1, narg, nres);
989 } 1002 }
990 else if EQ("call") { 1003 else if EQ("pcall") {
991 int narg = getnum; 1004 int narg = getnum;
992 int nres = getnum; 1005 int nres = getnum;
993 lua_pcall(L1, narg, nres, 0); 1006 lua_pcall(L1, narg, nres, 0);
@@ -1139,6 +1152,7 @@ static void checkfinalmem (void) {
1139 1152
1140int luaB_opentests (lua_State *L) { 1153int luaB_opentests (lua_State *L) {
1141 void *ud; 1154 void *ud;
1155 lua_atpanic(L, &tpanic);
1142 atexit(checkfinalmem); 1156 atexit(checkfinalmem);
1143 lua_assert(lua_getallocf(L, &ud) == debug_realloc); 1157 lua_assert(lua_getallocf(L, &ud) == debug_realloc);
1144 lua_assert(ud == cast(void *, &l_memcontrol)); 1158 lua_assert(ud == cast(void *, &l_memcontrol));