lua-users home
lua-l archive

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


In case anyone else is trying to do something similar, copying the
source class table seems to fix things:
function extends(baseClass)
  local new_class = {}
  for k, v in pairs(baseClass) do
    new_class[k] = baseClass[k]
  end
  if baseClass.new ~= nil then
    function new_class:new(...)
      local new_inst = baseClass:new(unpack(arg))
      if self.OnCreate ~= nil then
        self.OnCreate(new_inst)
      end
      return new_inst
    end
  end
  return new_class
end

 - Jeremy

"Help I suffer from the oxymoron Corporate Security."


> -------- Original Message --------
> Subject: .properties and inheritance problems
> From: jdarling@eonclash.com
> Date: Wed, October 11, 2006 9:22 am
> To: Lua list <lua@bazar2.conectiva.com.br>
> 
> I have an interesting problem that I just can't seem to figure out.  I'm
> using the inheritsFrom example source provided from the tutorial at:
> http://lua-users.org/wiki/InheritanceTutorial.  Everything seems fine
> until I use it against an object that is created outside of Lua that
> has property readers and writers (getters and setters).
> 
> The properties just go away.  For example, my class surfaced to Lua
> looks like:
> TGUIElement = {__index={x = cfunc_GetX, y = cfunc_GetY}, __newindex={x =
> cfunc_SetX, y = cfunc_SetY}}
> (Although the actual implementation is different where index and
> newindex point to cfunctions)
> 
> Now if I create a TGUIElement everything works fine.  Use the code:
> TLabel = inheritsFrom(TGUIElement)
> function TLabel:OnDraw()
> end
> 
> Looking at TLabel everything appears to be fine.  Try to access L.x
> though and I get an error saying that its nil.  So how would I go about
> modifying the inheritsFrom source so that it propigates down the
> existing properties?
> 
>  - Jeremy
> 
> "Help I suffer from the oxymoron Corporate Security."