summaryrefslogtreecommitdiff
path: root/Runtime/Lua/LuaBind/LuaBindLFunction.cpp
blob: b4688979525aa565105784939ebe7677179f85b0 (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
#include "LuaBindLFunction.h"
#include "LuaBindHelper.h"

namespace LuaBind
{

	LuaFunction::LuaFunction(const char* func)
	{
		method = func;
	}

	void LuaFunction::operator = (const char* func)
	{
		method = func;
	}

	void LuaFunction::AddInt(State& state, int n)
	{
		state.Push(n);
		++argc;
	}

	void LuaFunction::AddFloat(State& state, float n)
	{
		state.Push(n);
		++argc;
	}

	void LuaFunction::AddNil(State& state)
	{
		state.PushNil();
		++argc;
	}

	void LuaFunction::AddBool(State& state, bool b)
	{
		state.Push(b);
		++argc;
	}

	void LuaFunction::AddString(State& state, const char* str)
	{
		state.Push(str);
		++argc;
	}

	void LuaFunction::AddTable(State& state, INativeTable& tb)
	{
		tb.CastToTable(state);
		++argc;
	}

	void LuaFunction::Invoke(State& state, int nReturns)
	{
		if (state.GetGlobalField(method))
		{
			int funcIdx = -1 - argc;
			lua_replace(state, funcIdx);
			state.Call(argc, nReturns);
		}
	}

}