diff options
Diffstat (limited to 'client/luawidget.cc')
-rw-r--r-- | client/luawidget.cc | 91 |
1 files changed, 66 insertions, 25 deletions
diff --git a/client/luawidget.cc b/client/luawidget.cc index 529984c..ba64257 100644 --- a/client/luawidget.cc +++ b/client/luawidget.cc @@ -29,6 +29,8 @@ #include "widgets.h" +#include "debug.h" + #define LUA_SRC "lua" /** @@ -196,20 +198,32 @@ static int wdg_set_valid(lua_State *L) return 0; } -static int wdg_checked(lua_State *L) +#define WDG_METHS \ + {"name", wdg_name},\ + {"type", wdg_type},\ + {"value", wdg_value},\ + {"setValue", wdg_set_value},\ + {"enabled", wdg_enabled},\ + {"setEnabled", wdg_set_enabled},\ + {"visible", wdg_visible},\ + {"setVisible", wdg_set_visible},\ + {"valid", wdg_valid},\ + {"setValid", wdg_set_valid} + +static int wdg_chk_checked(lua_State *L) { wdg_userdata *wdgu; wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox"); luaL_argcheck(L, wdgu, 1, "checkbox expected"); - CheckBox *cmb = (CheckBox*)wdgu->widget; - lua_pushboolean(L, cmb->checked()); + CheckBox *chk = (CheckBox*)wdgu->widget; + lua_pushboolean(L, chk->checked()); return 1; } -static int wdg_set_checked(lua_State *L) +static int wdg_chk_set_checked(lua_State *L) { wdg_userdata *wdgu; @@ -218,27 +232,47 @@ static int wdg_set_checked(lua_State *L) bool val = luaL_checkbool(L, 2); - CheckBox *cmb = (CheckBox*)wdgu->widget; - cmb->setChecked(val); + CheckBox *chk = (CheckBox*)wdgu->widget; + chk->setChecked(val); return 0; } -#define WDG_METHS \ - {"name", wdg_name},\ - {"type", wdg_type},\ - {"value", wdg_value},\ - {"setValue", wdg_set_value},\ - {"enabled", wdg_enabled},\ - {"setEnabled", wdg_set_enabled},\ - {"visible", wdg_visible},\ - {"setVisible", wdg_set_visible},\ - {"valid", wdg_valid},\ - {"setValid", wdg_set_valid} +#define WDG_CMBBOX_METHS \ + {"checked", wdg_chk_checked},\ + {"setChecked", wdg_chk_set_checked} + +static int wdg_cmb_clear(lua_State *L) +{ + wdg_userdata *wdgu; + + wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox"); + luaL_argcheck(L, wdgu, 1, "combobox expected"); + + ComboBox *cmb = (ComboBox*)wdgu->widget; + cmb->clear(); + + return 0; +} + +static int wdg_cmb_add_item(lua_State *L) +{ + wdg_userdata *wdgu; + + wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox"); + luaL_argcheck(L, wdgu, 1, "combobox expected"); + + QString val = luaL_checkstring(L, 2); + + ComboBox *cmb = (ComboBox*)wdgu->widget; + cmb->addItem(val); + + return 0; +} #define WDG_CHKBOX_METHS \ - {"checked", wdg_checked},\ - {"setChecked", wdg_set_checked} + {"clear", wdg_cmb_clear},\ + {"addItem", wdg_cmb_add_item} static const struct luaL_Reg wdg_meths[] = { WDG_METHS, {NULL, NULL} }; @@ -246,6 +280,9 @@ static const struct luaL_Reg wdg_meths[] = { static const struct luaL_Reg wdg_chkbox_meths[] = { WDG_METHS, WDG_CHKBOX_METHS, {NULL, NULL} }; +static const struct luaL_Reg wdg_cmbbox_meths[] = { + WDG_METHS, WDG_CMBBOX_METHS, {NULL, NULL} }; + static const struct luaL_Reg wdg_chk_meths[] = { {NULL, NULL} @@ -256,12 +293,10 @@ int wdg_make_widget(lua_State *L, Widget *widget) wdg_userdata *wdgu; wdgu = (wdg_userdata *)lua_newuserdata(L, sizeof(wdg_userdata)); - if(widget->type() == "checkbox") { - luaL_getmetatable(L, "CheckBox"); - } else { - luaL_getmetatable(L, "Widget"); - } - + if(widget->type() == "combobox") luaL_getmetatable(L, "ComboBox"); + else if(widget->type() == "checkbox") luaL_getmetatable(L, "CheckBox"); + else luaL_getmetatable(L, "Widget"); + lua_setmetatable(L, -2); wdgu->widget = widget; @@ -283,5 +318,11 @@ void register_widget(lua_State *L) lua_rawset(L, -3); luaL_register(L, NULL, wdg_chkbox_meths); + luaL_newmetatable(L, "ComboBox"); + lua_pushliteral(L, "__index"); + lua_pushvalue(L, -2); + lua_rawset(L, -3); + luaL_register(L, NULL, wdg_cmbbox_meths); + } |