This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Kouksi44's profile picture

Lua any way of late binding?

Started by Kouksi44, 11 November 2014 - 04:47 PM
Kouksi44 #1
Posted 11 November 2014 - 05:47 PM
Hey everybody,

I am currently working with coroutines and the "run code in background" code from the tutorials section!

My problem is that I am creating the coroutine first when a specific function is called but in the overwritten os.pullEventRaw() he checks if my coroutine is suspended like this:
 if coroutine.status( coFoo ) == "suspended" 
. If any event occurs before the coroutine is created this will just error because the program can´t find "coFoo" .

I don´t really know how to check if a variable does even exist or(as the title says) there is some kind of late binding ?

Maybe some of you know anything that helps me :)/>

Thank you in advance !

mfG Kouksi44
ElvishJerricco #2
Posted 11 November 2014 - 06:07 PM

local coFoo
...
if not coFoo then
    coFoo = makeMyCoroutine()
end

if coroutine.status(coFoo) == "suspended" then
...
Kouksi44 #3
Posted 11 November 2014 - 06:27 PM
well…. I am feeling pretty damn stupid right now xD thank you !