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

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -