summaryrefslogtreecommitdiff
path: root/Runtime/Lua/LuaHelper.cpp
blob: a47d5282f3a3295c599ec1340e62e804478b47e2 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "LuaHelper.h"

using namespace LuaBind;

template <>
Rect State::GetValue < Rect >(int idx, const Rect value)
{
    Rect rect;
    rect.x = GetField<float>(idx, 1, 0);
    rect.y = GetField<float>(idx, 2, 0);
    rect.width = GetField<float>(idx, 3, 0);
    rect.height = GetField<float>(idx, 4, 0);
    return rect;
}

template <>
Internal::Vector2 State::GetValue < Internal::Vector2 >(int idx, const Internal::Vector2 value)
{
    Internal::Vector2 v2;
    v2.x = GetField<float>(idx, 1, 0);
    v2.y = GetField<float>(idx, 2, 0);
    return v2;
}

int LuaHelper::Call(const char* func, const char* params, ...)
{
    return 1;
}

void LuaHelper::OnRegisterNativeClass(LuaBind::State& state, int cls, std::string clsName, std::string pkgName)
{
	// 填充类型的元数据
	lua_newtable(state);
	int typeIdx = state.GetTop();
	state.Push("native");
	state.SetField(typeIdx, "mode");
	state.Push(clsName);
	state.SetField(typeIdx, "name");
	state.Push(pkgName);
	state.SetField(typeIdx, "package");
	state.Push(pkgName + '.' + clsName);
	state.SetField(typeIdx, "fullName");
	lua_setfield(state, cls, "_type");
}

bool LuaHelper::IsType(LuaBind::State& state, const char* typeName, int idx)
{
	int top = state.GetTop();
	cc8* type = luaL_typename(state, idx);
	if (strcmp(type, typeName) == 0)
		return true;
	state.GetField(idx, "_type");
	if (!state.IsTable(-1))
	{
		state.Pop(1);
		return false;
	}
	std::string tname = state.GetField(-1, "fullName", "");
	bool bIsType = tname == typeName;
	state.SetTop(top);
	return bIsType;
}

bool LuaHelper::InstantiateClass(LuaBind::State& state, const char* classFullName)
{
    return false;
}