From 208e23de77ad6d104f13a0bb591ae16c4a805fe9 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 26 Oct 2021 23:20:45 +0800 Subject: *load image async --- Runtime/Scripting/Resource/Resource.bind.cpp | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Runtime/Scripting/Resource/Resource.bind.cpp (limited to 'Runtime/Scripting/Resource/Resource.bind.cpp') diff --git a/Runtime/Scripting/Resource/Resource.bind.cpp b/Runtime/Scripting/Resource/Resource.bind.cpp new file mode 100644 index 0000000..b4ba025 --- /dev/null +++ b/Runtime/Scripting/Resource/Resource.bind.cpp @@ -0,0 +1,41 @@ +#include "Runtime/Lua/LuaHelper.h" +#include "Runtime/Debug/Log.h" +#include "Runtime/FileSystem/ImageJobs.h" + +using namespace LuaBind; + +// Resource.LoadImageDataAsync(path, callback) +int ReadImageDataAsync(lua_State* L) +{ + LUA_BIND_STATE(L); + LUA_BIND_CHECK(L, "TF"); + + cc8* path = state.GetValue(1, ""); + + ReadImageFileJob* job = new ReadImageFileJob(state.GetVM(), 2, path); + + JobSystem::Instance()->AddJobAtEnd(job); + + return 0; +} + +static luaL_Reg funcs[] = { + {"ReadImageDataAsync", ReadImageDataAsync}, + {0, 0} +}; + +int luaopen_GameLab_Engine_Resource(lua_State* L) +{ + log_info("Scripting", "luaopen_GameLab_Engine_Resource()"); + + LUA_BIND_STATE(L); + + state.PushGlobalNamespace(); + state.PushNamespace("GameLab"); + state.PushNamespace("Engine"); + state.PushNamespace("Resource"); + + state.RegisterMethods(funcs); + + return 1; +} \ No newline at end of file -- cgit v1.1-26-g67d0