Blob Blame History Raw
--- configure	2004-07-02 03:46:35.000000000 +0200
+++ configure	2006-08-24 21:37:10.000000000 +0200
@@ -5548,13 +5548,13 @@ fi
 
 fi
 
-    echo "$as_me:$LINENO: checking for luaopen_base in -llualib" >&5
-echo $ECHO_N "checking for luaopen_base in -llualib... $ECHO_C" >&6
+    echo "$as_me:$LINENO: checking for luaopen_base in -llua" >&5
+echo $ECHO_N "checking for luaopen_base in -llua... $ECHO_C" >&6
 if test "${ac_cv_lib_lualib_luaopen_base+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   ac_check_lib_save_LIBS=$LIBS
-LIBS="-llualib $LUA_LIBS -lm $LIBS"
+LIBS="-llua $LUA_LIBS -lm $LIBS"
 cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
@@ -5613,15 +5613,15 @@ fi
 echo "$as_me:$LINENO: result: $ac_cv_lib_lualib_luaopen_base" >&5
 echo "${ECHO_T}$ac_cv_lib_lualib_luaopen_base" >&6
 if test $ac_cv_lib_lualib_luaopen_base = yes; then
-  LUA_LIBS="$LUA_LIBS -llualib"
+  LUA_LIBS="$LUA_LIBS -llua"
 else
-  echo "$as_me:$LINENO: checking for luaopen_base in -llualib50" >&5
-echo $ECHO_N "checking for luaopen_base in -llualib50... $ECHO_C" >&6
+  echo "$as_me:$LINENO: checking for luaopen_base in -llua50" >&5
+echo $ECHO_N "checking for luaopen_base in -llua50... $ECHO_C" >&6
 if test "${ac_cv_lib_lualib50_luaopen_base+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   ac_check_lib_save_LIBS=$LIBS
-LIBS="-llualib50 $LUA_LIBS -lm $LIBS"
+LIBS="-llua50 $LUA_LIBS -lm $LIBS"
 cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
@@ -5680,15 +5680,15 @@ fi
 echo "$as_me:$LINENO: result: $ac_cv_lib_lualib50_luaopen_base" >&5
 echo "${ECHO_T}$ac_cv_lib_lualib50_luaopen_base" >&6
 if test $ac_cv_lib_lualib50_luaopen_base = yes; then
-  LUA_LIBS="$LUA_LIBS -llualib50"
+  LUA_LIBS="$LUA_LIBS -llua50"
 else
-  echo "$as_me:$LINENO: checking for luaopen_base in -llualib5.0" >&5
-echo $ECHO_N "checking for luaopen_base in -llualib5.0... $ECHO_C" >&6
+  echo "$as_me:$LINENO: checking for luaopen_base in -llua5.0" >&5
+echo $ECHO_N "checking for luaopen_base in -llua5.0... $ECHO_C" >&6
 if test "${ac_cv_lib_lualib5_0_luaopen_base+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   ac_check_lib_save_LIBS=$LIBS
-LIBS="-llualib5.0 $LUA_LIBS -lm $LIBS"
+LIBS="-llua5.0 $LUA_LIBS -lm $LIBS"
 cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
@@ -5747,7 +5747,7 @@ fi
 echo "$as_me:$LINENO: result: $ac_cv_lib_lualib5_0_luaopen_base" >&5
 echo "${ECHO_T}$ac_cv_lib_lualib5_0_luaopen_base" >&6
 if test $ac_cv_lib_lualib5_0_luaopen_base = yes; then
-  LUA_LIBS="$LUA_LIBS -llualib5.0"
+  LUA_LIBS="$LUA_LIBS -llua5.0"
 else
   { { echo "$as_me:$LINENO: error: Lualib5 is required" >&5
 echo "$as_me: error: Lualib5 is required" >&2;}
--- configure.in	2004-06-12 13:55:49.000000000 +0200
+++ configure.in	2006-08-24 21:37:12.000000000 +0200
@@ -263,9 +263,9 @@ else
     AC_CHECK_LIB(lua50, lua_setfenv, LUA_LIBS="$LUA_LIBS -llua50",
     AC_CHECK_LIB(lua5.0, lua_setfenv, LUA_LIBS="$LUA_LIBS -llua5.0",
     [AC_MSG_ERROR(Lua5 is required)], -lm), -lm), -lm)
-    AC_CHECK_LIB(lualib, luaopen_base, LUA_LIBS="$LUA_LIBS -llualib",
-    AC_CHECK_LIB(lualib50, luaopen_base, LUA_LIBS="$LUA_LIBS -llualib50",
-    AC_CHECK_LIB(lualib5.0, luaopen_base, LUA_LIBS="$LUA_LIBS -llualib5.0",
+    AC_CHECK_LIB(lualib, luaopen_base, LUA_LIBS="$LUA_LIBS -llua",
+    AC_CHECK_LIB(lualib50, luaopen_base, LUA_LIBS="$LUA_LIBS -llua50",
+    AC_CHECK_LIB(lualib5.0, luaopen_base, LUA_LIBS="$LUA_LIBS -llua5.0",
     [AC_MSG_ERROR(Lualib5 is required)], $LUA_LIBS -lm), $LUA_LIBS -lm),$LUA_LIBS -lm)
 fi
 
--- src/stratagus/script.c	2004-06-27 00:38:18.000000000 +0200
+++ src/stratagus/script.c	2006-08-24 21:40:55.000000000 +0200
@@ -323,9 +323,9 @@ int LuaToBoolean(lua_State* l, int narg)
 void CclGarbageCollect(int fast)
 {
 	DebugPrint("Garbage collect (before): %d/%d\n" _C_
-		lua_getgccount(Lua) _C_ lua_getgcthreshold(Lua));
+		lua_getgccount(Lua) _C_ lua_gc(Lua));
 
-	lua_setgcthreshold(Lua, 0);
+	lua_gc(Lua, LUA_GCCOLLECT, 0);
 
 	DebugPrint("Garbage collect (after): %d/%d\n" _C_
 		lua_getgccount(Lua) _C_ lua_getgcthreshold(Lua));
--- src/stratagus/script.c.hdg	2006-11-14 23:35:39.000000000 +0100
+++ src/stratagus/script.c	2006-11-14 23:35:39.000000000 +0100
@@ -149,6 +149,23 @@
 	return status;
 }
 
+static int traceback (lua_State *L) {
+  lua_getfield(L, LUA_GLOBALSINDEX, "debug");
+  if (!lua_istable(L, -1)) {
+    lua_pop(L, 1);
+    return 1;
+  }
+  lua_getfield(L, -1, "traceback");
+  if (!lua_isfunction(L, -1)) {
+    lua_pop(L, 2);
+    return 1;
+  }
+  lua_pushvalue(L, 1);  /* pass error message */
+  lua_pushinteger(L, 2);  /* skip this function and traceback */
+  lua_call(L, 2, 1);  /* call debug.traceback */
+  return 1;
+}
+
 /**
 **  Call a lua function
 **
@@ -159,19 +176,19 @@
 */
 int LuaCall(int narg, int clear)
 {
-	int status;
-	int base;
-
-	base = lua_gettop(Lua) - narg;      // function index
-	lua_pushliteral(Lua, "_TRACEBACK");
-	lua_rawget(Lua, LUA_GLOBALSINDEX);  // get traceback function
-	lua_insert(Lua, base);              // put it under chunk and args
-	signal(SIGINT, laction);
-	status = lua_pcall(Lua, narg, (clear ? 0 : LUA_MULTRET), base);
-	signal(SIGINT, SIG_DFL);
-	lua_remove(Lua, base);              // remove traceback function
-
-	return report(status);
+  int status;
+  int base = lua_gettop(Lua) - narg;  /* function index */
+  lua_pushcfunction(Lua, traceback);  /* push traceback function */
+  lua_insert(Lua, base);  /* put it under chunk and args */
+  signal(SIGINT, laction);
+  status = lua_pcall(Lua, narg, (clear ? 0 : LUA_MULTRET), base);
+  signal(SIGINT, SIG_DFL);
+  lua_remove(Lua, base);  /* remove traceback function */
+#if 0
+  /* force a complete garbage collection in case of errors */
+  if (status != 0) lua_gc(Lua, LUA_GCCOLLECT, 0);
+#endif
+  return report(status);
 }
 
 /**
--- src/ai/script_ai.c.hdg	2004-06-25 01:37:30.000000000 +0200
+++ src/ai/script_ai.c	2006-11-14 23:42:58.000000000 +0100
@@ -349,7 +349,11 @@
 	lua_call(l, 1, 1);
 	lua_pushstring(l, "name");
 	lua_gettable(l, -2);
-	aitype->FunctionName = strdup(lua_tostring(l, -1));
+	value = lua_tostring(l, -1);
+	if (value)
+		aitype->FunctionName = strdup(lua_tostring(l, -1));
+	else
+		aitype->FunctionName = NULL;
 	lua_pop(l, 2); // FIXME : check if this value is correct.
 	// We can have opcode of this function with string.dump(function)
 	// Problems are for sub functions...