YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

classhing table members across instances
mariusco
#1 Posted : Wednesday, July 25, 2018 7:40:28 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/11/2018(UTC)
Posts: 4
Location: toronto

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
If a class has a member as a table which has a inner table
the subtable value is not instance agnostic. Behave as a
static. Here is the example:

Code:

class MyClass
{
    _name=null;
    _a={

        A="A",
        C = {
            c="c",
        }
    };
    _ta = null;

    constructor(name)
    {
        _a=clone _a;
        _name=name;
        _a.A=name;
        base.constructor(MyClass,"SWITCH","V,G","ops",this);
    }

    function enume()
    {
        print("FOR: ------- " + _name + "------ \r\n")
        foreach(k, d in _a)
        {
            print(_name + ": "+ k + " = " + d + "\r\n");
            if(typeof d == "table")
            {
                foreach(kk, dd in d)
                {
                    print("       "+kk + ": " + kk + " = " + dd + "\r\n");
                }
            }
        }
    }

}


    local v1 = MyClass("instance 1");
    local v2 = MyClass("instance 2");

    print("BEFORE ----------------------\n");
    v1.enume();
    v2.enume();



    v1._a.A="V1-A";
    v2._a.A="V2-A";
    v1._a.C.c="V1-C";
    v2._a.C.c="V2-C";

    print("AFTER ------------------\n");
    v1.enume();
    v2.enume();

    //Thermostat1_go();
    return True;



RUN:

BEFORE ----------------------
FOR: ------- instance 1------
instance 1: A = instance 1
instance 1: C = (table : 0x0x110abd0)
       c: c = c
FOR: ------- instance 2------
instance 2: A = instance 2
instance 2: C = (table : 0x0x110abd0)
       c: c = c
AFTER ------------------
FOR: ------- instance 1------
instance 1: A = V1-A
instance 1: C = (table : 0x0x110abd0)
       c: c = V2-C                           <<< ????  should be V1-C
FOR: ------- instance 2------
instance 2: A = V2-A
instance 2: C = (table : 0x0x110abd0)
       c: c = V2-C
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.059 seconds.