From dd8f8b36791112761b7a5b16a7a9dbb1b72284f5 Mon Sep 17 00:00:00 2001
From: Paul Dufresne <dufresnep@zoho.com>
Date: Sat, 1 Jul 2023 15:41:53 -0400
Subject: [PATCH 2/2] replace some lua_objlen by lua_rawlen

---
 engine/ai/script_ai.cpp        | 20 ++++++++++----------
 engine/game/construct.cpp      |  2 +-
 engine/game/groups.cpp         |  2 +-
 engine/game/script_missile.cpp |  2 +-
 engine/game/script_player.cpp  | 12 ++++++------
 engine/game/script_spell.cpp   | 10 +++++-----
 engine/game/selection.cpp      |  2 +-
 engine/game/trigger.cpp        |  8 ++++----
 engine/include/script.h        |  2 +-
 9 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/engine/ai/script_ai.cpp b/engine/ai/script_ai.cpp
index 92843191..47f53d49 100644
--- a/engine/ai/script_ai.cpp
+++ b/engine/ai/script_ai.cpp
@@ -202,7 +202,7 @@ static int CclDefineAiHelper(lua_State *l)
 	for (j = 0; j < args; ++j)
 	{
 		LuaCheckTable(l, j + 1);
-		subargs = lua_objlen(l, j + 1);
+		subargs = lua_rawlen(l, j + 1);
 		k = 0;
 		value = LuaToString(l, j + 1, k + 1);
 		++k;
@@ -606,7 +606,7 @@ static int CclAiForce(lua_State *l)
 		LuaError(l, "Force out of range: %d" _C_ force);
 	}
 
-	args = lua_objlen(l, 2);
+	args = lua_rawlen(l, 2);
 	for (j = 0; j < args; ++j)
 	{
 		lua_rawgeti(l, 2, j + 1);
@@ -910,7 +910,7 @@ static int CclDefineAiPlayer(lua_State *l)
 		else if (!strcmp(value, "force"))
 		{
 			LuaCheckTable(l, j + 1);
-			subargs = lua_objlen(l, j + 1);
+			subargs = lua_rawlen(l, j + 1);
 			k = 0;
 			i = LuaToNumber(l, j + 1, k + 1);
 			++k;
@@ -961,7 +961,7 @@ static int CclDefineAiPlayer(lua_State *l)
 
 					lua_rawgeti(l, j + 1, k + 1);
 					LuaCheckTable(l, -1);
-					subsubargs = lua_objlen(l, -1);
+					subsubargs = lua_rawlen(l, -1);
 					for (subk = 0; subk < subsubargs; ++subk)
 					{
 						int num;
@@ -984,7 +984,7 @@ static int CclDefineAiPlayer(lua_State *l)
 
 					lua_rawgeti(l, j + 1, k + 1);
 					LuaCheckTable(l, -1);
-					subsubargs = lua_objlen(l, -1);
+					subsubargs = lua_rawlen(l, -1);
 					for (subk = 0; subk < subsubargs; ++subk)
 					{
 						int num;
@@ -1017,7 +1017,7 @@ static int CclDefineAiPlayer(lua_State *l)
 		else if (!strcmp(value, "needed"))
 		{
 			LuaCheckTable(l, j + 1);
-			subargs = lua_objlen(l, j + 1);
+			subargs = lua_rawlen(l, j + 1);
 			for (k = 0; k < subargs; ++k)
 			{
 				const char *type;
@@ -1032,7 +1032,7 @@ static int CclDefineAiPlayer(lua_State *l)
 		else if (!strcmp(value, "need-mask"))
 		{
 			LuaCheckTable(l, j + 1);
-			subargs = lua_objlen(l, j + 1);
+			subargs = lua_rawlen(l, j + 1);
 			for (k = 0; k < subargs; ++k)
 			{
 				const char *type;
@@ -1048,7 +1048,7 @@ static int CclDefineAiPlayer(lua_State *l)
 		else if (!strcmp(value, "unit-type"))
 		{
 			LuaCheckTable(l, j + 1);
-			subargs = lua_objlen(l, j + 1);
+			subargs = lua_rawlen(l, j + 1);
 			i = 0;
 			if (subargs)
 			{
@@ -1070,7 +1070,7 @@ static int CclDefineAiPlayer(lua_State *l)
 		else if (!strcmp(value, "building"))
 		{
 			LuaCheckTable(l, j + 1);
-			subargs = lua_objlen(l, j + 1);
+			subargs = lua_rawlen(l, j + 1);
 			for (k = 0; k < subargs; ++k)
 			{
 				const char *ident;
@@ -1096,7 +1096,7 @@ static int CclDefineAiPlayer(lua_State *l)
 		else if (!strcmp(value, "repair-workers"))
 		{
 			LuaCheckTable(l, j + 1);
-			subargs = lua_objlen(l, j + 1);
+			subargs = lua_rawlen(l, j + 1);
 			for (k = 0; k < subargs; ++k)
 			{
 				int num;
diff --git a/engine/game/construct.cpp b/engine/game/construct.cpp
index ccadbd61..f5ee27fe 100644
--- a/engine/game/construct.cpp
+++ b/engine/game/construct.cpp
@@ -220,7 +220,7 @@ static int CclDefineConstruction(lua_State *l)
 				construction->ShadowFile.Height = h;
 			}
 		} else if (!strcmp(value, "Constructions")) {
-			subargs = lua_objlen(l, -1);
+			subargs = lua_rawlen(l, -1);
 			for (k = 0; k < subargs; ++k) {
 				int percent;
 				ConstructionFileType file;
diff --git a/engine/game/groups.cpp b/engine/game/groups.cpp
index f2f015b3..18c895b0 100644
--- a/engine/game/groups.cpp
+++ b/engine/game/groups.cpp
@@ -252,7 +252,7 @@ static int CclGroup(lua_State *l)
 	grp = &Groups[(int)LuaToNumber(l, 1)];
 	grp->NumUnits = LuaToNumber(l, 2);
 	i = 0;
-	args = lua_objlen(l, 3);
+	args = lua_rawlen(l, 3);
 	for (j = 0; j < args; ++j) {
 		const char *str;
 
diff --git a/engine/game/script_missile.cpp b/engine/game/script_missile.cpp
index 807aaf2b..bfcb24d1 100644
--- a/engine/game/script_missile.cpp
+++ b/engine/game/script_missile.cpp
@@ -307,7 +307,7 @@ static int CclDefineBurningBuilding(lua_State *l)
 
 		const char *value;
 		BurningBuildingFrame *ptr = new BurningBuildingFrame;
-		int subargs = lua_objlen(l, j + 1);
+		int subargs = lua_rawlen(l, j + 1);
 
 		for (int k = 0; k < subargs; ++k) {
 			value = LuaToString(l, j + 1, k + 1);
diff --git a/engine/game/script_player.cpp b/engine/game/script_player.cpp
index 27b5b769..673c79cb 100644
--- a/engine/game/script_player.cpp
+++ b/engine/game/script_player.cpp
@@ -144,7 +144,7 @@ static int CclPlayer(lua_State *l)
 			player->StartY = LuaToNumber(l, j + 1, 2);
 		} else if (!strcmp(value, "production-rate")) {
 			LuaCheckTable(l, j + 1);
-			subargs = lua_objlen(l, j + 1);
+			subargs = lua_rawlen(l, j + 1);
 			for (k = 0; k < subargs; ++k) {
 				value = LuaToString(l, j + 1, k + 1);
 				++k;
@@ -161,7 +161,7 @@ static int CclPlayer(lua_State *l)
 			}
 		} else if (!strcmp(value, "stored-resources")) {
 			LuaCheckTable(l, j + 1);
-			subargs = lua_objlen(l, j + 1);
+			subargs = lua_rawlen(l, j + 1);
 			for (k = 0; k < subargs; ++k) {
 				value = LuaToString(l, j + 1, k + 1);
 				++k;
@@ -178,7 +178,7 @@ static int CclPlayer(lua_State *l)
 			}
 		} else if (!strcmp(value, "storage-capacity")) {
 			LuaCheckTable(l, j + 1);
-			subargs = lua_objlen(l, j + 1);
+			subargs = lua_rawlen(l, j + 1);
 			for (k = 0; k < subargs; ++k) {
 				value = LuaToString(l, j + 1, k + 1);
 				++k;
@@ -217,7 +217,7 @@ static int CclPlayer(lua_State *l)
 			player->TotalKills = LuaToNumber(l, j + 1);
 		} else if (!strcmp(value, "total-resources")) {
 			LuaCheckTable(l, j + 1);
-			subargs = lua_objlen(l, j + 1);
+			subargs = lua_rawlen(l, j + 1);
 			if (subargs != MaxCosts) {
 				LuaError(l, "Wrong number of total-resources: %d" _C_ i);
 			}
@@ -457,13 +457,13 @@ static int CclDefinePlayerColors(lua_State *l)
 	LuaCheckArgs(l, 1);
 	LuaCheckTable(l, 1);
 
-	args = lua_objlen(l, 1);
+	args = lua_rawlen(l, 1);
 	for (i = 0; i < args; ++i) {
 		PlayerColorNames[i / 2] = LuaToString(l, 1, i + 1);
 		++i;
 		lua_rawgeti(l, 1, i + 1);
 		LuaCheckTable(l, -1);
-		numcolors = lua_objlen(l, -1);
+		numcolors = lua_rawlen(l, -1);
 		if (numcolors != PlayerColorIndexCount) {
 			LuaError(l, "You should use %d colors (See DefinePlayerColorIndex())" _C_ PlayerColorIndexCount);
 		}
diff --git a/engine/game/script_spell.cpp b/engine/game/script_spell.cpp
index b437e1c8..d5f9b2f3 100644
--- a/engine/game/script_spell.cpp
+++ b/engine/game/script_spell.cpp
@@ -66,7 +66,7 @@ static void CclSpellMissileLocation(lua_State *l, SpellActionMissileLocation *lo
 	Assert(location != NULL);
 
 	LuaCheckTable(l, -1);
-	args = lua_objlen(l, -1);
+	args = lua_rawlen(l, -1);
 	j = 0;
 
 	for (j = 0; j < args; ++j) {
@@ -107,7 +107,7 @@ static SpellActionType *CclSpellAction(lua_State *l)
 	int j;
 
 	LuaCheckTable(l, -1);
-	args = lua_objlen(l, -1);
+	args = lua_rawlen(l, -1);
 	j = 0;
 
 	value = LuaToString(l, -1, j + 1);
@@ -435,7 +435,7 @@ static void CclSpellCondition(lua_State *l, ConditionInfo *condition)
 	}
 	//  Now parse the list and set values.
 	LuaCheckTable(l, -1);
-	args = lua_objlen(l, -1);
+	args = lua_rawlen(l, -1);
 	for (j = 0; j < args; ++j) {
 		value = LuaToString(l, -1, j + 1);
 		++j;
@@ -499,7 +499,7 @@ static void CclSpellAutocast(lua_State *l, AutoCastInfo *autocast)
 	int j;
 
 	LuaCheckTable(l, -1);
-	args = lua_objlen(l, -1);
+	args = lua_rawlen(l, -1);
 	for (j = 0; j < args; ++j) {
 		value = LuaToString(l, -1, j + 1);
 		++j;
@@ -594,7 +594,7 @@ static int CclDefineSpell(lua_State *l)
 			int k;
 
 			LuaCheckTable(l, i + 1);
-			subargs = lua_objlen(l, i + 1);
+			subargs = lua_rawlen(l, i + 1);
 			for (k = 0; k < subargs; ++k) {
 				lua_rawgeti(l, i + 1, k + 1);
 				spell->Action.push_back(CclSpellAction(l));
diff --git a/engine/game/selection.cpp b/engine/game/selection.cpp
index 95090195..ff297df3 100644
--- a/engine/game/selection.cpp
+++ b/engine/game/selection.cpp
@@ -1161,7 +1161,7 @@ static int CclSelection(lua_State *l)
 	InitSelections();
 	NumSelected = LuaToNumber(l, 1);
 	i = 0;
-	args = lua_objlen(l, 2);
+	args = lua_rawlen(l, 2);
 	for (j = 0; j < args; ++j) {
 		const char *str;
 
diff --git a/engine/game/trigger.cpp b/engine/game/trigger.cpp
index d097dc7b..5fca0ba7 100644
--- a/engine/game/trigger.cpp
+++ b/engine/game/trigger.cpp
@@ -572,7 +572,7 @@ static int CclAddTrigger(lua_State *l)
 		lua_gettable(l, LUA_GLOBALSINDEX);
 	}
 
-	i = lua_objlen(l, -1);
+	i = lua_rawlen(l, -1);
 	if (ActiveTriggers && !ActiveTriggers[i / 2]) {
 		lua_pushnil(l);
 		lua_rawseti(l, -2, i + 1);
@@ -632,7 +632,7 @@ static int TriggerExecuteAction(int script)
 	ret = 0;
 
 	lua_rawgeti(Lua, -1, script + 1);
-	args = lua_objlen(Lua, -1);
+	args = lua_rawlen(Lua, -1);
 	for (j = 0; j < args; ++j) {
 		lua_rawgeti(Lua, -1, j + 1);
 		LuaCall(0, 0);
@@ -672,7 +672,7 @@ void TriggersEachCycle(void)
 
 	lua_pushstring(Lua, "_triggers_");
 	lua_gettable(Lua, LUA_GLOBALSINDEX);
-	triggers = lua_objlen(Lua, -1);
+	triggers = lua_rawlen(Lua, -1);
 
 	if (nextTrigger >= triggers) {
 		nextTrigger = 0;
@@ -733,7 +733,7 @@ void SaveTriggers(CFile *file)
 
 	lua_pushstring(Lua, "_triggers_");
 	lua_gettable(Lua, LUA_GLOBALSINDEX);
-	triggers = lua_objlen(Lua, -1);
+	triggers = lua_rawlen(Lua, -1);
 
 	file->printf("SetActiveTriggers(");
 	for (i = 0; i < triggers; i += 2) {
diff --git a/engine/include/script.h b/engine/include/script.h
index 54d6319c..57f682ae 100644
--- a/engine/include/script.h
+++ b/engine/include/script.h
@@ -91,7 +91,7 @@ extern int LuaCall(int narg, int clear, bool exitOnError = true);
 
 #define LuaCheckTableSize(l, index, size) \
 	do { \
-		if (!lua_istable((l), (index)) || lua_objlen((l), (index)) != (size)) { \
+		if (!lua_istable((l), (index)) || lua_rawlen((l), (index)) != (size)) { \
 			LuaError(l, "incorrect argument"); \
 		} \
 	} while (0)
-- 
2.39.3

