blob: ba5691f9fe9ae07b412734dbea66021601d65a63 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#include "Runtime/Lua/LuaHelper.h"
#include "Runtime/Debug/Log.h"
#include "Runtime/FileSystem/FileJobs.h"
// IO.ReadFiles({}, callback)
int ReadFilesAsync(lua_State* L)
{
LUA_BIND_STATE(L);
LUA_BIND_CHECK(L, "TF");
std::vector<std::string> files;
for (int i = 1; true; ++i)
{
state.GetField(1, i);
if (lua_type(L, -1) != LUA_TSTRING)
{
lua_pop(L, 1);
break;
}
const char* f = lua_tostring(L, -1);
state.Pop(1);
files.push_back(f);
}
ReadFilesJob* job = new ReadFilesJob(state.GetVM());
job->files = files;
job->callback.SetRef(state, 2);
JobSystem::Instance()->AddJobAtEnd(job);
return 0;
}
static luaL_Reg ioFuncs[] = {
{"ReadFilesAsync", ReadFilesAsync},
{0, 0}
};
int luaopen_GameLab_IO(lua_State* L)
{
log_info("Scripting", "luaopen_GameLab_IO()");
LUA_BIND_STATE(L);
state.PushGlobalNamespace();
state.PushNamespace("GameLab");
state.PushNamespace("IO");
state.RegisterMethods(ioFuncs);
return 1;
}
|