I am sure there is something conceptual I am just not getting but after days of messing around I need someone far smarter than me to tell me how I can do things.
I basically want to wait for a function in a table to return a result and then continue on with the code. So accept it works asynchronously but deal with it.
I have done a cut down example which I hope will explain what I mean.
manager.lua
local manager = {} local manager\_mt = { \_\_index = manager } function manager:new() return setmetatable( manager, manager\_mt ) end function manager:upload() local function networkListener( event ) if ( event.isError ) then print( "Network error!") return false elseif ( event.phase == "ended" ) then print ( "Upload complete!" ) return true end end return network.upload( "http://127.0.0.1/restapi.php", "POST", networkListener, "object.json", system.DocumentsDirectory, "application/json" ) end return manager
main.lua
local manager = require("manager") manager = manager:new() if(manager:upload()==true) then print("Yippee, upload has been completed, do the next thing") end
So I am basically looking to find out if “manager:upload()” has been successful and respond accordingly. I am trying to take an OO approach to things. I have used network.upload just as an example, it could be a number of different things.
Is what I am trying to do possible, do I have to do it a totally different way in Lua?
Any help would be greatly appreciated.
Thanks