Perhaps this is a strange question.
Whenever there are callbacks, code gets written backwards and is very nested and that bugs me. For example;
local f2 = function() print "LAST" end local f1 = function() print "FIRST"; timer.performWithDelay(100,f2) end local runMyFuncs = function() timer.performWithDelay(100,f1) -- returns immediately end runMyFuncs() print "AFTER"
If I run this, it will print AFTER, then FIRST, then LAST. because runMyFuncs returns immediately.
Is there anyway that I can make execution hold up until something is complete? Basically so it works like this;
local f2 = function() print "LAST"; \*\*EXECUTION GOES FROM HERE\*\*; end local f1 = function() print "FIRST"; timer.performWithDelay(100,f2) end local runMyFuncs = function() timer.performWithDelay(100,f1) \*\*TO HERE\*\* end runMyFuncs() print "AFTER"
It isn’t just with timers, it’s network calls and anything where there is a callback.
The code always ends up in this strange nested backwards spaghetti - callbacks, in callbacks, in callbacks.
Probably it’s just how LUA is, I don’t know.