local self = {
super = mimas.Widget() -- userdata
}
-- wrap calls from C
function super.paint(p, w, h)
SpecialEdit = {}
setmetatable(SpecialEdit, mimas.LineEdit_mt)
-- calling SpecialEdit() should do the following things
-- 1. create userdata
-- 2. set new table as uservale ---> self
-- 3. create new lua thread and install "self" on the stack
-- 4. set access to userdata from self ---> self.super = userdata
-- 5. set "SpecialEdit" as metatable for "self" ---> setmetatable(self, SpecialEdit)
-- 6. return "self"
-- This is a callback called from the C side. The call goes as follows
-- 1. the object's lua_thread's stack contains "self", ready to be used.
-- 2. call self.textChanged(self, text)
function SpecialEdit:textChanged(text)
-- just to show that self is accessed by the callback with custom values ("owner").
self.owner:doSomething()
-- call a native method
-- "hide" is found in mimas.LineEdit_mt ---> LineEdit_mt.hide(self)
-- the userdata is found in self ---> LineEdit *c_obj = self.super // C pseudo-code
-- call the class method ---> c_obj->hide()
self:hide(nil)
end
In order to handle the callbacks, I would create a single lua thread (which could keep "self" in it's stack).