lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,
 
  I was wondering if anyone with some SWIG-lua experience could answer a couple of questions. First it's pretty cool to see an office version of SWIG-lua around!  My problem is with trying to identify class instances within lua.  In the following example, I am using lua to handle callbacks for a GUI (note this is a contrived example): 
 
bt = Button()
bt:setHandler( 'BasicButton' )
bt.textures = { normal = CreateTexture( 'normal.tga' ), down = CreateTexture( 'down.tga' ) }
 
BasicButton = {}
function BasicButton:onMouseDown( button, x, y )
    if button == Mouse_Left then
        self:setState( Button_Down )
        self:setTexture( self.textures.down )
    end
end
 
function BasicButton:onMouseUp( button, x, y )
    if button == Mouse_Left then
        self:setState( Button_Up )
        self:setTexture( self.textures.up )
    end
end
 
  I think there are several problems here.  First I believe that bt isn't a table, it's userdata.  How can I attach attributes to it?  I was thinking that I could use the bt as a key to a table of attributes as mentioned in the Lua book but I don't think it will work for callbacks.  The C callback would push the SWIG pointer onto the stack but wouldn't it be a new userdata and hence a different key? 
  The other problem would be that the callbacks would push a Widget for 'self' and not a Button.  So I think the metatable won't have the button entries for its member functions.  Is there a way to cast?
 
Leigh