Overwriting an instance Codea function

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)

But how can I do this with a Codea function such as keyboard?

--# Main
function setup()
    foo = Foo()
    --This is what I wan to do, but it can't access self.
    --foo.keyboard = new_keyboard


function keyboard(key)

--overwrite with this function
function new_keyboard(key)
    print(self.x.." Bar "..key)

--# Foo
Foo = class()

function Foo:init(x)
    -- you can accept and set parameters here
    self.x = "Foo"

--I want to overwrite this.
function Foo:keyboard(key)
    print(self.x.." "..key)

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.

@Briarfox: If I am understanding you correctly, then I think what you need to do is make new_keyboard take ‘self’ as the first parameter:

function new_keyboard(self, key)
    print(self.x.." Bar "..key)

Remember that:

function Foo:keyboard(key)

is just shorthand for:

function Foo.keyboard(self, key)

Thus, it follows that all a function needs to do in order to be a “member function” is take the instance it operates on as the first parameter.

If that’s not what you are asking, then sorry, I misunderstood.

lol Thank you @toadkick That was simple. I had assumed self wouldn’t work as keyboard passes key as the first param. I overlooked how self worked :slight_smile: