[oolua] Re: Get derived class instead of base

  • From: SteelRat <steelrat@xxxxxxx>
  • To: oolua@xxxxxxxxxxxxx
  • Date: Wed, 28 May 2014 18:21:51 +0400

Yes, i rewrote code for new container class inherited from default - it returns correct object now. Thanks for answer.


28.05.2014 18:01, Liam Devine пишет:
On 28/05/14 12:36, SteelRat wrote:
  What is normal behavior for such cases in OOLua?

What you are seeing is normal behaviour. OOLua keeps a userdata cache,
so if create and then store the instance in the container, from Lua, it
will know the derived class. This is until the instance in no longer
reachable in Lua and the gc has ran. When the gc is ran, the
corresponding userdata entry is removed from the cache. I imagine you
are, at this point, retrieving the instance from the container and the
method returns a base instance hence it is a base instance in Lua. In
C++, for the rare occasion you would need this, you would use a
dynamic_cast yet OOLua has no such cast.



Other related posts: