463 posts
Location
Star Wars
Posted 19 February 2016 - 10:12 PM
How can I overwrite a native funcion without a crash?
For example:
local oldTerm = {}
for k, v in pairs(term) do
oldTerm[k] = v
end
term["write"] = function(...) --Here crashes
<CODE>
end
Computercraft in minecraft version 1.7.10
Edited on 19 February 2016 - 09:13 PM
957 posts
Location
Web Development
Posted 19 February 2016 - 10:38 PM
Whats the error?
1023 posts
Posted 19 February 2016 - 10:42 PM
and what specifically are you overwriting the function with?
This for example would work, so it is most likely what you are overwriting it with.
local oldWrite = term.write
term.write = function(...)
return oldWrite(...)
end
463 posts
Location
Star Wars
Posted 19 February 2016 - 11:06 PM
Oh sorry, I did this:
term["write"] = function(...)
write(...)
end
But I forgot, that write use term.write. :D/>
7083 posts
Location
Tasmania (AU)
Posted 21 February 2016 - 08:54 AM
At least with the term API, it's not
intended that you do this. The idea is that you construct a new table filled with your replacement functions for those in term, then pass that as an argument to
term.redirect() (which returns the previous such table used - computers start off using
term.native(), but
multishell typically changes that to a
window).
If you attempt to override the whole term API, then you'll likely get undesirable results if a script makes use of multiple display objects.
Edited on 21 February 2016 - 07:55 AM