Posted 27 October 2012 - 07:30 AM
From what I understand, in LUA you can reference a function using a variable. For example:
So, in ComputerCraft we have a handy "term.redirect()" function. Perhaps, instead of passing this a monitor object we could pass it a table of functions? Seeing as you can access LUA table entries by non int based keys (for example a["cake"] = true) then why not use the function names (so a valid term.redirect() call would need a table with entries such as var["write"] = function(n), var["setCursor"] = function(n,n) and so on). This way, we could create our own objects, and redirect the computer's output to them.
For example, a remote control program could use term.redirect() to redirect output to its own functions that use rednet to send the output back to the controller.
a = function(n)
return n^2
end
print(a(2))
The above code will create a function, which takes a single variable and return its square.So, in ComputerCraft we have a handy "term.redirect()" function. Perhaps, instead of passing this a monitor object we could pass it a table of functions? Seeing as you can access LUA table entries by non int based keys (for example a["cake"] = true) then why not use the function names (so a valid term.redirect() call would need a table with entries such as var["write"] = function(n), var["setCursor"] = function(n,n) and so on). This way, we could create our own objects, and redirect the computer's output to them.
For example, a remote control program could use term.redirect() to redirect output to its own functions that use rednet to send the output back to the controller.