summaryrefslogtreecommitdiff
path: root/src/cat/LuaLabel.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-11-17 19:44:09 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-11-17 19:44:09 (GMT)
commit058a2edd75debbd0297f92572316daa704bd379f (patch)
treead303f091f9a08b209b91eb34a9fcad996a3de69 /src/cat/LuaLabel.cpp
parente3594aba9e05c6865d396418c028049cda92c2f3 (diff)
parent7a21ae192fe19868539956f3fe28e62b2c7c4429 (diff)
downloadpowder-058a2edd75debbd0297f92572316daa704bd379f.zip
powder-058a2edd75debbd0297f92572316daa704bd379f.tar.gz
Merge branch 'master' of github.com:FacialTurd/PowderToypp
Diffstat (limited to 'src/cat/LuaLabel.cpp')
-rw-r--r--src/cat/LuaLabel.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/cat/LuaLabel.cpp b/src/cat/LuaLabel.cpp
new file mode 100644
index 0000000..e2ca56d
--- /dev/null
+++ b/src/cat/LuaLabel.cpp
@@ -0,0 +1,56 @@
+extern "C"
+{
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+}
+
+#include <iostream>
+#include "LuaScriptInterface.h"
+#include "LuaLabel.h"
+#include "interface/Label.h"
+
+const char LuaLabel::className[] = "Label";
+
+#define method(class, name) {#name, &class::name}
+Luna<LuaLabel>::RegType LuaLabel::methods[] = {
+ method(LuaLabel, text),
+ method(LuaLabel, position),
+ method(LuaLabel, size),
+ method(LuaLabel, visible),
+ {0, 0}
+};
+
+LuaLabel::LuaLabel(lua_State * l) :
+ LuaComponent(l)
+{
+ this->l = l;
+ int posX = luaL_optinteger(l, 1, 0);
+ int posY = luaL_optinteger(l, 2, 0);
+ int sizeX = luaL_optinteger(l, 3, 10);
+ int sizeY = luaL_optinteger(l, 4, 10);
+ std::string text = luaL_optstring(l, 5, "");
+
+ label = new ui::Label(ui::Point(posX, posY), ui::Point(sizeX, sizeY), text);
+ component = label;
+}
+
+int LuaLabel::text(lua_State * l)
+{
+ int args = lua_gettop(l);
+ if(args)
+ {
+ luaL_checktype(l, 1, LUA_TSTRING);
+ label->SetText(lua_tostring(l, 1));
+ return 0;
+ }
+ else
+ {
+ lua_pushstring(l, label->GetText().c_str());
+ return 1;
+ }
+}
+
+LuaLabel::~LuaLabel()
+{
+} \ No newline at end of file