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

[Question] Overwrite an API function

Started by kelevra.1337, 03 April 2014 - 11:01 PM
kelevra.1337 #1
Posted 04 April 2014 - 01:01 AM
Hey everybody,

So im trying to overwriting an function in my little API for special usage. I can overwrite the function by just saying:


os.loadAPI("myAPI")
test = function()
  print("the function i want to use")
end
myAPI.test = test
myAPI.test()
-- prints "the function i want to use"

And that works fine if i just want to call that function. The problem is that other function from within the API still call the old version, not the one i created.

Is there any way to make that happen?
Lyqyd #2
Posted 04 April 2014 - 02:24 AM
Where it calls the function in your API, you probably have it just call test(), correct? Change it to myAPI.test() and it should work correctly.
kelevra.1337 #3
Posted 04 April 2014 - 10:30 PM
Thanks for the answer, does that mean i have to reference everything in my API with "myAPI.function"/"myAPI.variable"?