Added back attack and movement functions, missionData is now part of units

This commit is contained in:
Pax1601
2023-01-17 22:17:20 +01:00
parent 280799b27a
commit b77f271183
18 changed files with 388 additions and 225 deletions

View File

@@ -4,7 +4,7 @@
void DllExport stackUpdate(lua_State* L, int& stackDepth, int initialStack = 0);
void DllExport stackPop(lua_State* L, int popDepth = 1);
void DllExport stackClean(lua_State* L, int stackDepth);
json::value DllExport luaTableToJSON(lua_State* L, int index);
json::value DllExport luaTableToJSON(lua_State* L, int index, bool logKeys = false);
#define STACK_UPDATE stackUpdate(L, stackDepth, initialStack);
#define STACK_INIT int stackDepth = 0; int initialStack = 0; stackUpdate(L, initialStack);

View File

@@ -18,7 +18,7 @@ void stackClean(lua_State* L, int stackDepth)
lua_pop(L, stackDepth);
}
json::value luaTableToJSON(lua_State* L, int index)
json::value luaTableToJSON(lua_State* L, int index, bool logKeys)
{
auto json = json::value::object();
@@ -32,9 +32,13 @@ json::value luaTableToJSON(lua_State* L, int index)
{
lua_pushvalue(L, -2);
const char* key = lua_tostring(L, -1);
if (logKeys)
{
log(key);
}
if (lua_istable(L, -2))
{
json[to_wstring(key)] = luaTableToJSON(L, -2);
json[to_wstring(key)] = luaTableToJSON(L, -2, logKeys);
}
else if (lua_isnumber(L, -2))
{
@@ -44,7 +48,7 @@ json::value luaTableToJSON(lua_State* L, int index)
{
json[to_wstring(key)] = json::value::boolean(lua_toboolean(L, -2));
}
else if (lua_isstring(L, -2)) // Keep last, only checks if it can be stringified (not if it actually IS a string)
else if (lua_isstring(L, -2)) // Keep last, lua_isstring only checks if it can be stringified (not if it actually IS a string)
{
json[to_wstring(key)] = json::value::string(to_wstring(lua_tostring(L, -2)));
}