Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Class that Contains an object, can it be done?

I tried something like:

WorldObj = class(obj, ...)

function WorldObj:init()
for o=1, #vargs do
if not vargs[objName] then
self.objs[vargs[objName]] = vargs[obj]

-- however, I can't figure it out.
-- inheritance is not a problem figuring out. But not everything "is-a" object. What of "has-a" or "contains-a" object classes?



  • edited March 31 Posts: 110

    I'm not sure what you're trying to do exactly, but Ill try to help anyway. Are you trying to store a class within a class? This is fairly easy. Here's an example:

    classA = class()
    classB = class()
    function classB:init()
         -- code here
    function classA:init()
        self.c = classB()

    (I haven't used classes in a while, so my bad if it doesn't work properly)
    My other guess is that you're trying to store a table in a class or something. Here's another example:

    C = class()
    function C:init() = { } -- table stored in a class

    Sorry if I hadn't helped you. :confused:
    Edit: I have changed a bit of the top code.

Sign In or Register to comment.