I not sure if what I am trying to do is possible, hopefully someone will be able to shed some light. I want to pass a function name to a second function and get the second function to call the first one.
Main(SubMain,"blah")
function Main(pName,pstuff)
execute function (pName)
stuff........
end
function SubMain()
stuff here........
end
Can it be done ?
TIA,
JC
Remember, don't sweat the petty things
and don't pet the sweaty things.......
Variables are handled as functions.
So any variable can be passed off as a function
If it doesnt error out that is.
function Main(pName, pStuff)
if (type(pName) == "function") then
result = pName() -- result is whatever pName returns
else
-- Not a function!@#?!
end
print(result)
end
function MySub()
-- blah blah blah
return "value" -- returns back to main.
end
function SubMain()
screen:print(0,0,"test",Color.new(255,0,0))
end
function Main(func)
while true do
screen:clear(Color.new(255,255,255))
func()
screen.flip()
end
end
Main(SubMain)
function SubMain()
screen:print(0,0,"test",Color.new(255,0,0))
end
function Main(func)
while true do
screen:clear(Color.new(255,255,255))
func()
screen.flip()
end
end
Main(SubMain)
No error-checking.
No way to terminate loop.
screen:clear() doesnt need to be called.
screen.flip() -- might not be needed.
Too much extra code and not enough explination.
Sorry I dont mean to nitpick at your code, but I thought it might help!