Permalink
Browse files

fix #6088

  • Loading branch information...
rt
rt committed Nov 24, 2018
1 parent 871cc9b commit 96c1e01bb2213b1af79b4eb2e803667d61338244
Showing with 9 additions and 8 deletions.
  1. +4 −1 rts/Lua/LuaParser.cpp
  2. +4 −5 rts/Lua/LuaVFS.cpp
  3. +1 −2 rts/Lua/LuaVFS.h
@@ -15,6 +15,7 @@
#include "LuaConstGame.h"
#include "LuaConstEngine.h"
#include "LuaIO.h"
#include "LuaVFS.h"
#include "LuaUtils.h"
#include "Game/GameVersion.h"
@@ -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();
@@ -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);
@@ -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);
@@ -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;
}
@@ -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));
@@ -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); }
/******************************************************************************/
@@ -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);

0 comments on commit 96c1e01

Please sign in to comment.