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

Scope headaches.

Started by Lyqyd, 02 May 2012 - 03:24 AM
Lyqyd #1
Posted 02 May 2012 - 05:24 AM
I've got some slight modifications to make to read() that I'd like to apply to all calls to it on a per-computer basis. I'm trying to do this such that it would be possible to use on SMP when one doesn't have access to the ROM (which is where it's implemented right now). The best way I could think of was a straight function-replacement in startup, but I have the nasty feeling that that change is going out of scope as soon as startup is finished executing, since I'm seeing the behavior of the usual read() there instead of the modified behavior. Everything works fine if the modified read() is implemented in bios.lua instead. Any pointers on what the issue is? Is it really just a scope issue?

[These changes implement event-driven multitasking (for rednet daemons), and are already tested and proven to work. I'm just trying to make the system portable at this point.]
Mads #2
Posted 29 June 2012 - 07:37 PM
As long as the computer is not shut down, it should work. Atleast it works like that in Lua, I don't know about CC.
Cloudy #3
Posted 29 June 2012 - 08:01 PM
Try

rawset(_G, "read", yourNewRead)
Lyqyd #4
Posted 30 June 2012 - 01:22 AM
Holy crap, topic necromancy. I got this working weeks ago using a rawset() call. Thanks for the (somewhat too late) help, Cloudy.
Cloudy #5
Posted 30 June 2012 - 08:23 AM
I didn't realise that the topic had been bumped from May. Sorry!

mad: You really shouldn't bump topics this old!
Mads #6
Posted 30 June 2012 - 10:52 AM
Cloudy: You should neither!