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

Can't Pass General functions through rednet

Started by Lewisk3, 01 July 2015 - 05:07 AM
Lewisk3 #1
Posted 01 July 2015 - 07:07 AM
ok i have been trying to create a remote desktop using the _G.fs

i do


lua> id, m = rednet.receive()
COMPUTER 2:
lua> rednet.send(computer 1 id, _G.fs)
COMPUTER 1:
lua> m
{} <-- empty table?!?!
lua>
COMPUTER 2:
ok now watch this
lua> g = getfenv()._G.fs
lua> rednet.send(computer 1 id, g)
COMPUTER 1
lua> m
table {numbers}
lua> _G.fs = m
lua> exit()
shell> ls
hell 131: attempt to index a nil value!
shell 45: attempt to index a nil value!
-- whats wrong here?

please tell me what im doing wrong?
thanks
Bomb Bloke #2
Posted 01 July 2015 - 07:20 AM
You can't transmit functions via modems (and by extension, nor can you send them via rednet). That includes functions in tables. Coroutines are also off limits.

The code here may get you started on a solution.
Lupus590 #3
Posted 01 July 2015 - 12:32 PM
a (slightly complex) way round this could be to send the source of the function to the other computer
or have a special network layer which realise there is a function there and allows remote calls of that function (I have explained that very badly)
valithor #4
Posted 01 July 2015 - 12:43 PM
a (slightly complex) way round this could be to send the source of the function to the other computer
or have a special network layer which realise there is a function there and allows remote calls of that function (I have explained that very badly)

The easier solution is to have the "host" computer's entire term api overwritten to where it sends the function name along with the arguments, and the one you are accessing the reflection from to catch these rednet messages and run the term function with the args in the message. The second computer would then capture all events and transmit them to the host computer and the host would would need to catch all these messages and os.queue the events. When those steps are done you have successfully set up a remote desktop.

note: This is very spammy to rednet… but there really isn't a easier way to reflect in real time.

edit:

Just realized i managed to more or less explain the topic bomb bloke linked without having actually clicked on it.
Edited on 01 July 2015 - 10:44 AM