Skip to content

Commit

Permalink
fix #6088
Browse files Browse the repository at this point in the history
  • Loading branch information
rt committed Nov 24, 2018
1 parent 871cc9b commit 96c1e01
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
5 changes: 4 additions & 1 deletion rts/Lua/LuaParser.cpp
Expand Up @@ -15,6 +15,7 @@
#include "LuaConstGame.h"
#include "LuaConstEngine.h"
#include "LuaIO.h"
#include "LuaVFS.h"
#include "LuaUtils.h"

#include "Game/GameVersion.h"
Expand Down Expand Up @@ -158,7 +159,7 @@ void LuaParser::SetupEnv(bool synced)
EndTable();

#if (!defined(UNITSYNC) && !defined(DEDICATED))
// not relevant for most LuaParsers, but entries are of value to defsParser
// irrelevant for most LuaParsers except defsParser
GetTable("Game");
LuaConstGame::PushEntries(L);
EndTable();
Expand All @@ -169,6 +170,8 @@ void LuaParser::SetupEnv(bool synced)
EndTable();

GetTable("VFS");
// no LuaConstVFS, but this will do
LuaVFS::PushCommon(L);
AddFunc("DirList", DirList);
AddFunc("SubDirs", SubDirs);
AddFunc("Include", Include);
Expand Down
9 changes: 4 additions & 5 deletions rts/Lua/LuaVFS.cpp
Expand Up @@ -51,6 +51,8 @@ bool LuaVFS::PushCommon(lua_State* L)
HSTR_PUSH_CFUNC(L, "UnpackS32", UnpackS32);
HSTR_PUSH_CFUNC(L, "UnpackF32", UnpackF32);

// compression should be safe in synced context
HSTR_PUSH_CFUNC(L, "ZlibCompress", ZlibCompress);
HSTR_PUSH_CFUNC(L, "ZlibDecompress", ZlibDecompress);
HSTR_PUSH_CFUNC(L, "CalculateHash", CalculateHash);

Expand Down Expand Up @@ -90,8 +92,6 @@ bool LuaVFS::PushUnsynced(lua_State* L)
HSTR_PUSH_CFUNC(L, "MapArchive", MapArchive);
HSTR_PUSH_CFUNC(L, "UnmapArchive", UnmapArchive);

HSTR_PUSH_CFUNC(L, "ZlibCompress", ZlibCompress);

return true;
}

Expand Down Expand Up @@ -656,8 +656,7 @@ int UnpackType(lua_State* L)
if (tableCount < 0)
tableCount = maxCount;

tableCount = std::min((int)maxCount, tableCount);
lua_newtable(L);
lua_createtable(L, tableCount = std::min((int)maxCount, tableCount), 0);
for (int i = 0; i < tableCount; i++) {
lua_pushnumber(L, *(reinterpret_cast<const T*>(str) + i));
lua_rawseti(L, -2, (i + 1));
Expand All @@ -672,7 +671,7 @@ int LuaVFS::UnpackU32(lua_State* L) { return UnpackType<std::uint32_t>(L); }
int LuaVFS::UnpackS8(lua_State* L) { return UnpackType<std::int8_t>(L); }
int LuaVFS::UnpackS16(lua_State* L) { return UnpackType<std::int16_t>(L); }
int LuaVFS::UnpackS32(lua_State* L) { return UnpackType<std::int32_t>(L); }
int LuaVFS::UnpackF32(lua_State* L) { return UnpackType<float>(L); }
int LuaVFS::UnpackF32(lua_State* L) { return UnpackType<float>(L); }


/******************************************************************************/
Expand Down
3 changes: 1 addition & 2 deletions rts/Lua/LuaVFS.h
Expand Up @@ -10,14 +10,13 @@ struct lua_State;

class LuaVFS {
public:
static bool PushCommon(lua_State* L);
static bool PushSynced(lua_State* L);
static bool PushUnsynced(lua_State* L);

private:
static const std::string GetModes(lua_State* L, int index, bool synced);

static bool PushCommon(lua_State* L);

static int Include(lua_State* L, bool synced);
static int LoadFile(lua_State* L, bool synced);
static int FileExists(lua_State* L, bool synced);
Expand Down

0 comments on commit 96c1e01

Please sign in to comment.