Thread Tools Display Modes
Prev Previous Post   Next Post Next
09/14/14, 08:34 AM   #1
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
ZO_Object design question

I have a problem with the behaviour of ZO_Object's two methods. It's confusing at best for me. Currently I'm under the impression that it's simply copied from Programming in Lua.

ZO_Object:Subclass returns setmetatable({}, {__index = BaseClass}). The returned empty table cannot be used as a metatable itself... yet.

ZO_Object:New returns setmetatable({}, Class), and adds Class.__index = Class, so from now on the Class can be used as a metatable. Why does New, method that creates an instance, modify the class? Is there a reason to have a subclass incomplete until an instance is created?

And if you're interested what led me to this question, I want to replace the class (metatable) of an existing object with a subclass (instead of overriding several methods one by one). I never call New on the subclass, so I have to add __index myself due to the current design. It's simple, but I just can't grasp the concept why ZO_Object:Subclass() doesn't return a ready-to-use thing.
  Reply With Quote
 

ESOUI » Developer Discussions » Lua/XML Help » ZO_Object design question


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off