Skip to content

Commit b798272

Browse files
committed
Fixed LUA gamepath
1 parent 61dc3f7 commit b798272

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

source/lua_utils.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "lua_utils.hpp"
22
#include <string>
33
#include <string_view>
4+
#include <GarrysMod/Lua/LuaInterface.h>
45

56
namespace AsyncIO::LuaUtils {
67
void FindValue(GarrysMod::Lua::ILuaBase* LUA, std::string_view path) {
@@ -9,7 +10,7 @@ namespace AsyncIO::LuaUtils {
910
do {
1011
firstPos = endPos;
1112
endPos = path.find(".", endPos) + 1;
12-
std::string name{ path.substr(firstPos, endPos != 0 ? endPos - firstPos - 1 : path.size()) };
13+
std::string name{path.substr(firstPos, endPos != 0 ? endPos - firstPos - 1 : path.size())};
1314

1415
LUA->GetField(firstPos == 0 ? GarrysMod::Lua::INDEX_GLOBAL : -1, name.c_str());
1516
if (firstPos != 0) LUA->Remove(-2);
@@ -29,4 +30,9 @@ namespace AsyncIO::LuaUtils {
2930
LUA->Remove(-1 - results);
3031
return 0;
3132
}
33+
34+
const char* GetGamePath(GarrysMod::Lua::ILuaBase* LUA, const char* gamePath) {
35+
if (strcmp(gamePath, "LUA") == 0) return reinterpret_cast<GarrysMod::Lua::ILuaInterface*>(LUA)->GetPathID();
36+
return gamePath;
37+
}
3238
}

source/lua_utils.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ namespace AsyncIO::LuaUtils {
1111

1212
// Runs a function with given arguments on the stack. If function is nil, then just pushes nils as results and pops everything else
1313
int RunFunction(GarrysMod::Lua::ILuaBase* LUA, int args, int results);
14+
15+
// Converts LUA gamepath to filesystem gamepath
16+
const char* GetGamePath(GarrysMod::Lua::ILuaBase* LUA, const char* gamePath);
1417
}
1518

1619
#endif // ASYNCIO_LUAQUICKS

source/main.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ namespace Lua {
6262
LuaUtils::RunFunction(LUA, 4, 0);
6363

6464
MemAlloc_Free(data);
65-
}
66-
else {
65+
} else {
6766
LUA->PushNumber(FSASYNC_ERR_NOT_MINE);
6867
LuaUtils::RunFunction(LUA, 3, 0);
6968
}
@@ -147,14 +146,14 @@ namespace Lua {
147146

148147
LUA_FUNCTION(AsyncRead) {
149148
std::string fileName = LUA->CheckString(1);
150-
std::string gamePath = LUA->CheckString(2);
149+
const char* gamePath = LUA->CheckString(2);
151150

152151
if (!PathUtils::FixPath(fileName)) {
153152
LUA->PushNumber(FSASYNC_ERR_FILEOPEN);
154153
return 1;
155154
}
156155

157-
auto task = std::make_shared<AsyncReadTask>(fileName, gamePath);
156+
auto task = std::make_shared<AsyncReadTask>(fileName, LuaUtils::GetGamePath(LUA, gamePath));
158157
if (LUA->IsType(3, GarrysMod::Lua::Type::Function)) {
159158
LUA->Push(3);
160159
task->callbackRef = LUA->ReferenceCreate();
@@ -193,14 +192,14 @@ GMOD_MODULE_OPEN() {
193192
LUA->Pop();
194193
LUA->CreateTable();
195194
}
196-
LUA->PushCFunction(Lua::AsyncAppend);
197-
LUA->SetField(-2, "AsyncAppend");
195+
LUA->PushCFunction(Lua::AsyncAppend);
196+
LUA->SetField(-2, "AsyncAppend");
198197

199-
LUA->PushCFunction(Lua::AsyncWrite);
200-
LUA->SetField(-2, "AsyncWrite");
198+
LUA->PushCFunction(Lua::AsyncWrite);
199+
LUA->SetField(-2, "AsyncWrite");
201200

202-
LUA->PushCFunction(Lua::AsyncRead);
203-
LUA->SetField(-2, "AsyncRead");
201+
LUA->PushCFunction(Lua::AsyncRead);
202+
LUA->SetField(-2, "AsyncRead");
204203
LUA->SetField(GarrysMod::Lua::INDEX_GLOBAL, "asyncio");
205204

206205
return 0;

0 commit comments

Comments
 (0)