Blob Blame History Raw
diff -up boswars-2.7-src/engine/ai/ai.cpp.lua52 boswars-2.7-src/engine/ai/ai.cpp
--- boswars-2.7-src/engine/ai/ai.cpp.lua52	2013-06-02 14:41:06.000000000 +0200
+++ boswars-2.7-src/engine/ai/ai.cpp	2014-12-17 13:04:50.353074926 +0100
@@ -160,7 +160,7 @@ static void AiExecuteFunction(const char
 {
 	if (AiPlayer->AiType != NULL)
 	{
-		lua_getfield(Lua, LUA_GLOBALSINDEX, "AiTypes");
+		lua_getglobal(Lua, "AiTypes");
 		lua_getfield(Lua, -1, AiPlayer->AiType->Name.c_str());
 		lua_getfield(Lua, -1, field);
 		if (!lua_isnil(Lua, -1))
@@ -492,7 +492,7 @@ void AiInit(CPlayer *player)
 
 	// Initialize the AI state of the player if it has not been
 	// already initialized, i.e. we're not loading a saved game.
-	lua_getfield(Lua, LUA_GLOBALSINDEX, "AiState"); // stack: AiState
+	lua_getglobal(Lua, "AiState"); // stack: AiState
 	Assert(lua_istable(Lua, -1));
 	lua_pushnumber(Lua, player->Index);             // stack: AiState, player
 	lua_gettable(Lua, -2);                          // stack: AiState, AiState[player]
diff -up boswars-2.7-src/engine/ai/script_ai.cpp.lua52 boswars-2.7-src/engine/ai/script_ai.cpp
--- boswars-2.7-src/engine/ai/script_ai.cpp.lua52	2013-06-02 14:41:06.000000000 +0200
+++ boswars-2.7-src/engine/ai/script_ai.cpp	2014-12-17 13:04:50.354074903 +0100
@@ -340,7 +340,7 @@ static int CclDefineAiType(lua_State *l)
 	//
 	// Add to the AiTypes Lua variable.
 	//
-	lua_getfield(l, LUA_GLOBALSINDEX, "AiTypes");
+	lua_getglobal(l, "AiTypes");
 	lua_pushvalue(l, ident_index);
 	lua_pushvalue(l, aitype_index);
 	lua_settable(l, -3);
diff -up boswars-2.6.1-src/engine/game/trigger.cpp.lua-52 boswars-2.6.1-src/engine/game/trigger.cpp
--- boswars-2.6.1-src/engine/game/trigger.cpp.lua-52	2013-05-13 10:28:01.768320516 -0400
+++ boswars-2.6.1-src/engine/game/trigger.cpp	2013-05-13 10:31:23.566323544 -0400
@@ -557,17 +557,14 @@ static int CclAddTrigger(lua_State *l)
 	// Make a list of all triggers.
 	// A trigger is a pair of condition and action
 	//
-	lua_pushstring(l, "_triggers_");
-	lua_gettable(l, LUA_GLOBALSINDEX);
+	lua_getglobal(l, "_triggers_");
 
 	if (lua_isnil(l, -1)) {
 		DebugPrint("Trigger not set, defining trigger\n");
 		lua_pop(l, 1);
-		lua_pushstring(l, "_triggers_");
 		lua_newtable(l);
-		lua_settable(l, LUA_GLOBALSINDEX);
-		lua_pushstring(l, "_triggers_");
-		lua_gettable(l, LUA_GLOBALSINDEX);
+		lua_setglobal(l, "_triggers_");
+		lua_getglobal(l, "_triggers_");
 	}
 
 	i = lua_objlen(l, -1);
@@ -668,8 +665,7 @@ void TriggersEachCycle(void)
 	int triggers;
 	int base = lua_gettop(Lua);
 
-	lua_pushstring(Lua, "_triggers_");
-	lua_gettable(Lua, LUA_GLOBALSINDEX);
+	lua_getglobal(Lua, "_triggers_");
 	triggers = lua_objlen(Lua, -1);
 
 	if (nextTrigger >= triggers) {
@@ -729,8 +725,7 @@ void SaveTriggers(CFile *file)
 	int i;
 	int triggers;
 
-	lua_pushstring(Lua, "_triggers_");
-	lua_gettable(Lua, LUA_GLOBALSINDEX);
+	lua_getglobal(Lua, "_triggers_");
 	triggers = lua_objlen(Lua, -1);
 
 	file->printf("SetActiveTriggers(");
@@ -769,11 +764,9 @@ void InitTriggers(void)
 	//
 	// FIXME: choose the triggers for game type
 
-	lua_pushstring(Lua, "_triggers_");
-	lua_gettable(Lua, LUA_GLOBALSINDEX);
+	lua_getglobal(Lua, "_triggers_");
 	if (lua_isnil(Lua, -1)) {
-		lua_pushstring(Lua, "SinglePlayerTriggers");
-		lua_gettable(Lua, LUA_GLOBALSINDEX);
+		lua_getglobal(Lua, "SinglePlayerTriggers");
 		LuaCall(0, 1);
 	}
 	lua_pop(Lua, 1);
@@ -784,9 +777,8 @@ void InitTriggers(void)
 */
 void CleanTriggers(void)
 {
-	lua_pushstring(Lua, "_triggers_");
 	lua_pushnil(Lua);
-	lua_settable(Lua, LUA_GLOBALSINDEX);
+	lua_setglobal(Lua, "_triggers_");
 
 	nextTrigger = 0;
 
diff -up boswars-2.6.1-src/engine/include/script.h.lua-52 boswars-2.6.1-src/engine/include/script.h
--- boswars-2.6.1-src/engine/include/script.h.lua-52	2008-01-26 18:02:48.000000000 -0500
+++ boswars-2.6.1-src/engine/include/script.h	2013-05-13 10:19:18.323312662 -0400
@@ -46,6 +46,10 @@ extern "C" {
 }
 #endif
 
+#ifndef lua_objlen
+#define lua_objlen(L,i)        lua_rawlen(L, (i))
+#endif
+
 /*----------------------------------------------------------------------------
 --  Declarations
 ----------------------------------------------------------------------------*/
diff -up boswars-2.6.1-src/engine/sound/music.cpp.lua-52 boswars-2.6.1-src/engine/sound/music.cpp
--- boswars-2.6.1-src/engine/sound/music.cpp.lua-52	2013-05-13 10:33:00.200324994 -0400
+++ boswars-2.6.1-src/engine/sound/music.cpp	2013-05-13 10:33:21.527325314 -0400
@@ -84,8 +84,7 @@ void CheckMusicFinished(bool force)
 	SDL_UnlockMutex(MusicFinishedMutex);
 
 	if ((proceed || force) && SoundEnabled() && IsMusicEnabled() && CallbackMusic) {
-		lua_pushstring(Lua, "MusicStopped");
-		lua_gettable(Lua, LUA_GLOBALSINDEX);
+		lua_getglobal(Lua, "MusicStopped");
 		if (!lua_isfunction(Lua, -1)) {
 			fprintf(stderr, "No MusicStopped function in Lua\n");
 			StopMusic();
diff -up boswars-2.7-src/engine/stratagus/script.cpp.lua52 boswars-2.7-src/engine/stratagus/script.cpp
--- boswars-2.7-src/engine/stratagus/script.cpp.lua52	2013-06-02 14:41:07.000000000 +0200
+++ boswars-2.7-src/engine/stratagus/script.cpp	2014-12-17 13:04:50.354074903 +0100
@@ -156,8 +156,7 @@ static int report(int status, bool exitO
 */
 int luatraceback(lua_State *L)
 {
-	lua_pushliteral(L, "debug");
-	lua_gettable(L, LUA_GLOBALSINDEX);
+	lua_getglobal(L, "debug");
 	if (!lua_istable(L, -1)) {
 		lua_pop(L, 1);
 		return 1;
@@ -1428,7 +1427,7 @@ char *SaveGlobal(lua_State *l, bool is_r
 {
 	CSerializeLua serialize(l);
 	if (is_root) {
-		lua_pushvalue(l, LUA_GLOBALSINDEX);
+		lua_pushglobaltable(l);
 	}
 	CSerializeLua::Result result
 		= serialize.AppendLuaFields(lua_gettop(l), is_root);
@@ -1045,8 +1043,7 @@ void SavePreferences(void)
 	FILE *fd;
 	std::string path;
 
-	lua_pushstring(Lua, "preferences");
-	lua_gettable(Lua, LUA_GLOBALSINDEX);
+	lua_getglobal(Lua, "preferences");
 	if (lua_type(Lua, -1) == LUA_TTABLE) {
 		path = UserDirectory + "preferences.lua";
 
diff -up boswars-2.7-src/engine/ui/interface.cpp.lua52 boswars-2.7-src/engine/ui/interface.cpp
--- boswars-2.7-src/engine/ui/interface.cpp.lua52	2013-06-02 14:41:08.000000000 +0200
+++ boswars-2.7-src/engine/ui/interface.cpp	2014-12-17 13:04:50.354074903 +0100
@@ -474,8 +474,7 @@ bool HandleCommandKey(int key)
 	bool ret;
 	int base = lua_gettop(Lua);
 
-	lua_pushstring(Lua, "HandleCommandKey");
-	lua_gettable(Lua, LUA_GLOBALSINDEX);
+	lua_getglobal(Lua, "HandleCommandKey");
 	if (!lua_isfunction(Lua, -1)) {
 		DebugPrint("No HandleCommandKey function in lua.\n");
 		return false;
@@ -695,8 +695,7 @@ int HandleCheats(const std::string &inpu
 	}
 #endif
 	int base = lua_gettop(Lua);
-	lua_pushstring(Lua, "HandleCheats");
-	lua_gettable(Lua, LUA_GLOBALSINDEX);
+	lua_getglobal(Lua, "HandleCheats");
 	if (!lua_isfunction(Lua, -1)) {
 		DebugPrint("No HandleCheats function in lua.\n");
 	} else {
diff -up boswars-2.6.1-src/engine/ui/script_ui.cpp.lua-52 boswars-2.6.1-src/engine/ui/script_ui.cpp
--- boswars-2.6.1-src/engine/ui/script_ui.cpp.lua-52	2013-05-13 10:27:36.691320140 -0400
+++ boswars-2.6.1-src/engine/ui/script_ui.cpp	2013-05-13 10:27:41.517320212 -0400
@@ -703,15 +703,12 @@ static int CclDefineButtonStyle(lua_Stat
 */
 int AddHandler(lua_State *l)
 {
-	lua_pushstring(l, "_handlers_");
-	lua_gettable(l, LUA_GLOBALSINDEX);
+	lua_getglobal(l, "_handlers_");
 	if (lua_isnil(l, -1)) {
 		lua_pop(l, 1);
-		lua_pushstring(l, "_handlers_");
 		lua_newtable(l);
-		lua_settable(l, LUA_GLOBALSINDEX);
-		lua_pushstring(l, "_handlers_");
-		lua_gettable(l, LUA_GLOBALSINDEX);
+		lua_setglobal(l, "_handlers_");
+		lua_getglobal(l, "_handlers_");
 	}
 	lua_pushvalue(l, -2);
 	lua_rawseti(l, -2, HandleCount);
@@ -725,8 +722,7 @@ int AddHandler(lua_State *l)
 */
 void CallHandler(unsigned int handle, int value)
 {
-	lua_pushstring(Lua, "_handlers_");
-	lua_gettable(Lua, LUA_GLOBALSINDEX);
+	lua_getglobal(Lua, "_handlers_");
 	lua_rawgeti(Lua, -1, handle);
 	lua_pushnumber(Lua, value);
 	LuaCall(1, 1);