summaryrefslogtreecommitdiff
path: root/src/cat/LuaComponent.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cat/LuaComponent.cpp')
-rw-r--r--src/cat/LuaComponent.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/cat/LuaComponent.cpp b/src/cat/LuaComponent.cpp
new file mode 100644
index 0000000..8c2d3a4
--- /dev/null
+++ b/src/cat/LuaComponent.cpp
@@ -0,0 +1,82 @@
+extern "C"
+{
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+}
+
+#include <iostream>
+#include "LuaComponent.h"
+#include "LuaScriptInterface.h"
+#include "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;
+} \ No newline at end of file