summaryrefslogtreecommitdiff
path: root/src/cat/LuaComponent.cpp
blob: 028dfb58ce99fd0aba247f0f5c19e15165000c69 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifdef LUACONSOLE
extern "C"
{
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}

#include <iostream>
#include "LuaComponent.h"
#include "LuaScriptInterface.h"
#include "gui/interface/Component.h"


LuaComponent::LuaComponent(lua_State * l)
{
	this->l = l;

	lua_pushstring(l, "Luacon_ci");
	lua_gettable(l, LUA_REGISTRYINDEX);
	ci = (LuaScriptInterface*)lua_touserdata(l, -1);
	lua_pop(l, 1);
}

int LuaComponent::position(lua_State * l)
{
	int args = lua_gettop(l);
	if(args)
	{
		luaL_checktype(l, 1, LUA_TNUMBER);
		luaL_checktype(l, 2, LUA_TNUMBER);
		component->Position = ui::Point(lua_tointeger(l, 1), lua_tointeger(l, 2));
		return 0;
	}
	else
	{
		lua_pushinteger(l, component->Position.X);
		lua_pushinteger(l, component->Position.Y);
		return 2;
	}
}

int LuaComponent::size(lua_State * l)
{
	int args = lua_gettop(l);
	if(args)
	{
		luaL_checktype(l, 1, LUA_TNUMBER);
		luaL_checktype(l, 2, LUA_TNUMBER);
		component->Size = ui::Point(lua_tointeger(l, 1), lua_tointeger(l, 2));
		component->Invalidate();
		return 0;
	}
	else
	{
		lua_pushinteger(l, component->Size.X);
		lua_pushinteger(l, component->Size.Y);
		return 2;
	}
}

int LuaComponent::visible(lua_State * l)
{
	int args = lua_gettop(l);
	if(args)
	{
		luaL_checktype(l, 1, LUA_TBOOLEAN);
		component->Visible = lua_toboolean(l, 1);
		return 0;
	}
	else
	{
		lua_pushboolean(l, component->Visible);
		return 1;
	}
}

LuaComponent::~LuaComponent()
{
	if(component->GetParentWindow())
		component->GetParentWindow()->RemoveComponent(component);
	delete component;
}
#endif