Lua / Corona - How do I pass a function as a parameter and then call that function -
i trying pass function parameter in function.
high level have code creates popup window. when update popup window new text, want update action happens when user clicks on popup window. example first time update popup window, might change action to show popup window again new text. when user clicks on second
here sample code illustrate concept
function dosomething() print("this sample function") end function createpopup() local popup = display.newrect ... create display object function popup:close() popup.isvisible = false end function popup:update(options) if options.action function dg:touch(e) -- action passed options.action end end end popup:addeventlistener("touch",popup) return popup end local mypopup = createpopup() mypopup:update({action = dosomething()})
you can call this
function dosomething() print("this sample function") end function createpopup() local popup = display.newrect ... create display object function popup:close() popup.isvisible = false end function popup:update(options) if options.action function dg:touch(e) options.action() -- how call function end end end popup:addeventlistener("touch",popup) return popup end local mypopup = createpopup() mypopup:update({action = dosomething})
Comments
Post a Comment