diff options
author | chai <chaifix@163.com> | 2021-10-25 23:29:21 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-25 23:29:21 +0800 |
commit | 7ecf913256fb396e3027aac3318d996a716a52ef (patch) | |
tree | 4540835c881a63b665e2a692bf30115fd29e8bb0 /Runtime/Scripting/IO | |
parent | 0816cd70ca1a213b6ed872bcf3c0bf0912473722 (diff) |
+ job system
Diffstat (limited to 'Runtime/Scripting/IO')
-rw-r--r-- | Runtime/Scripting/IO/IO.bind.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Runtime/Scripting/IO/IO.bind.cpp b/Runtime/Scripting/IO/IO.bind.cpp new file mode 100644 index 0000000..d58d86f --- /dev/null +++ b/Runtime/Scripting/IO/IO.bind.cpp @@ -0,0 +1,51 @@ +#include "Runtime/Lua/LuaHelper.h" +#include "Runtime/Debug/Log.h" +#include "Runtime/FileSystem/FileJobs.h" + +// IO.ReadFiles({}, callback) +int ReadFiles(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[] = { + {"ReadFiles", ReadFiles}, + {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; +}
\ No newline at end of file |