summaryrefslogtreecommitdiff
path: root/Runtime/Scripting/Resource/Resource.bind.cpp
blob: 785115a0a6213f01487dd0827a451d2270c33a2a (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
#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, "SF");

	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;
}