I’m trying to find a way to overwrite a function in a class that specifically applies to an instance of that class. I can’t figure out how to pass it self so it can access it’s own variables. If it was a standard class method I could simply do:
foo = Foo()
foo.testFunc = newFunc(foo)
function newFunc(instance)
print(instance.x)
end
But how can I do this with a Codea function such as keyboard?
--# Main
function setup()
showKeyboard()
foo = Foo()
--This is what I wan to do, but it can't access self.
--foo.keyboard = new_keyboard
end
function keyboard(key)
foo:keyboard(key)
end
--overwrite with this function
function new_keyboard(key)
print(self.x.." Bar "..key)
end
--# Foo
Foo = class()
function Foo:init(x)
-- you can accept and set parameters here
self.x = "Foo"
end
--I want to overwrite this.
function Foo:keyboard(key)
print(self.x.." "..key)
end
This is in regards to Cider 7 and needing to overwrite the keyboard function on specific textboxes to remove show and hide keyboard to allow custom keypad to work.