From b3a9d6b10732f3f65ca0a24aa2a66275e24f8cd7 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Fri, 18 Apr 2014 20:23:52 +1000 Subject: Trying to add widget actions, but it's broken somehow. Think maybe Keyed is screwing it up? I need sleep. --- ClientHamr/GuiLua/GuiLua.c | 20 +++++++++++++++++- ClientHamr/GuiLua/skang.lua | 50 ++++++++++++++++++++++++++++++++++---------- ClientHamr/GuiLua/test.skang | 10 ++++----- 3 files changed, 63 insertions(+), 17 deletions(-) (limited to 'ClientHamr') diff --git a/ClientHamr/GuiLua/GuiLua.c b/ClientHamr/GuiLua/GuiLua.c index b42df1b..69fef14 100644 --- a/ClientHamr/GuiLua/GuiLua.c +++ b/ClientHamr/GuiLua/GuiLua.c @@ -587,6 +587,24 @@ static int widget(lua_State *L) return 0; } +static void _on_click(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + // TODO, pull the action out of the widget, then somehow magically send it to Lua. +} + +static int action(lua_State *L) +{ + Evas_Object *obj= lua_touserdata(L, 1); + char *action = "nada"; + + pull_lua(L, 2, "$", &action); +printf("Setting action %s\n", action); + // TODO - stuff the action into the widget somewhere. + evas_object_smart_callback_add(obj, "clicked", _on_click, L); + + return 0; +} + static int colour(lua_State *L) { // TODO - This is just a stub for now. @@ -594,7 +612,6 @@ static int colour(lua_State *L) return 0; } - static int window(lua_State *L) { globals *ourGlobals; @@ -737,6 +754,7 @@ int luaopen_libGuiLua(lua_State *L) push_lua(L, "@ ( { = $ $ & $ $acl } )", skang, THINGASM, skang, "Cwindow", "Opens our window.", window, "number,number,string", "GGG", 0); push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "clear", "The current skin is cleared of all widgets.", clear, 0); push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "widget", "Create a widget.", widget, 0); + push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "action", "Add an action to a widget.", action, 0); push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "Colour", "Change widget colours.", colour, 0); push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "loopWindow", "Run our windows main loop.", loopWindow, 0); push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "quit", "Quit, exit, remove thyself.", quit, 0); diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua index 6686e4d..e6b6725 100644 --- a/ClientHamr/GuiLua/skang.lua +++ b/ClientHamr/GuiLua/skang.lua @@ -696,9 +696,14 @@ __newindex = function (parent, key, value) if metaMum.__self.isKeyed then -- Deal with setting a new Keyed table entry. local newThing = copy(parent, key) + local newSelf = getmetatable(newThing).__self rawset(metaMum.__values, key, newThing) --- thingy = {names={key}, types={'table'}, parent=newThing, stuff=getmetatable(newThing).__self.stuff, } - thingy = {names={key}, types={'table'}, stuff=getmetatable(newThing).__self.stuff, } + thingy = {} + for k, v in pairs(newSelf) do + thingy[k] = v + end + thingy.names={key} + thingy.types={'table'} setmetatable(thingy, {__index = Thing}) -- To pick up isValid, pattern, and the other stuff by default. end end @@ -796,6 +801,7 @@ thingasm = function (names, ...) local params = {...} local new = false local parent + local set = true -- Check how we were called, and re arrange stuff to match. if 0 == #params then @@ -870,8 +876,20 @@ thingasm = function (names, ...) if '' == types then types = typ end thingy.types = csv2table(types) + if 'widget' == thingy.types[1] then + set = false + local args, err = loadstring('return ' .. thingy.widget) + if args then + setfenv(args, parent) + parent.W[name] = {widget = widget(args())} + else + print("ERROR - " .. err) + end + end + -- Deal with Keyed and tables. if 'Keyed' == thingy.types[1] then + set = false thingy.types[1] = 'table' thingy.isKeyed = true end @@ -883,14 +901,8 @@ thingasm = function (names, ...) setmetatable(thingy.default, thisMum) end - if 'widget' == thingy.types[1] then - local args, err = loadstring('return ' .. thingy.widget) - if args then - setfenv(args, parent) - parent.W[name] = {widget = widget(args())} - else - print("ERROR - " .. err) - end + if 'userdata' == thingy.types[1] then + set = false end -- Remove old names, then stash the Thing under all of it's new names. @@ -902,7 +914,7 @@ thingasm = function (names, ...) end -- This triggers the Mum.__newindex metamethod above. If nothing else, it triggers thingy.isValid() - if new and not metaMum.__self.isKeyed and ('widget' ~= thingy.types[1]) then parent[name] = thingy.default end + if new and set then parent[name] = thingy.default end end @@ -1013,6 +1025,20 @@ thingasm('nada', 'Do nothing.', function () --[[ This function intentionally lef local widgets = {} --thingasm{widgets, 'window', 'The window.', types='userdata'} thingasm{widgets, 'W', 'Holds all the widgets', types='Keyed'} +widgets.W{'widget', 'The widget.', types='userdata'} +widgets.W{'action,a', 'The action for the widget.', 'nada', types='string'} +local aIsValid = function (self, parent) + local result = Thing.isValid(self, parent) + + if result then + local value = parent[self.names[1] ] +print('NEW ACTION - ' .. self.names[1] .. ' = ' .. value) +--printTableStart(parent, '', 'parent') + action(parent.widget, value) + end + return result +end + widgets.W{'look,l', 'The look of the widget.', types='string'} widgets.W{'colour,color,c', 'The colours of the widget.', types='table'} widgets.W.c{'red,r', 'The red colour of the widget.', 255, types='number'} @@ -1030,6 +1056,8 @@ window = function(w, h, title, name) name = name or 'myWindow' local win = {} win.W = copy(widgets.W, name) + local wMum, wThingy = getStuffed(win.W, 'a') + wThingy.isValid = aIsValid win.window = Cwindow(w, h, title, name) return win end diff --git a/ClientHamr/GuiLua/test.skang b/ClientHamr/GuiLua/test.skang index a8ca105..340bb08 100644 --- a/ClientHamr/GuiLua/test.skang +++ b/ClientHamr/GuiLua/test.skang @@ -5,12 +5,12 @@ -- local other = require 'otherPackageName' -skang.clear() +-- This is a bit more verbose than I wanted. lol local win = skang.window(500, 500, "G'day planet.", 'testWindow') - - -skang.thingasm{win, 'quitter', 'Quits the skang window', types = 'widget', widget='"button", "Quit", 10, 10, 100, 50', required=true} ---quitter:action('quit') -- 'quit' is looked up in ThingSpace.commands, and translated into the Lua 'skang.quit()'. +skang.thingasm{win, 'quitter', 'Quits the skang window', types = 'widget', widget='"button", "Quit", 10, 10, 100, 50'} +skang.printTableStart(win.W.quitter, '', 'quitter') +win.W.quitter.action = 1 +win.W.quitter.action = 'quit' -- 'quit' is looked up in ThingSpace.commands, and translated into the Lua 'skang.quit()'. --other.foo = 'stuff' this.bar = 'things' -- cgit v1.1