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

Access derived class members from _inherited meta-method inside base class
SLC
#1 Posted : Wednesday, November 09, 2016 11:10:14 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/1/2013(UTC)
Posts: 30
Man
Location: Romania

Thanks: 3 times
Was thanked: 0 time(s) in 0 post(s)
An example is worth a thousand words. So here it is:
Code:
class Test
{
    function _inherited(attributes)
    {
        if (this.rawin("fn"))
            print("found");
        else
            print("not found");
    }
}

class SubTest extends Test
{
    function fn()
    {

    }
}


Outputs "not found". But according to the documentation, `this` should be the class that inherits `Test`. So I don't get it. What's the purpose of this meta-method if not for this.
absence
#2 Posted : Thursday, November 10, 2016 10:41:26 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 8/23/2014(UTC)
Posts: 102
Man
Location: Northern Germany & Lincolnshire, U.K.

Thanks: 1 times
Was thanked: 8 time(s) in 8 post(s)
it would work if it would be a function called later.
Not the rawin() is your issue, but the very fact the keyword "extends" calls _inherited on the base class RIGHT BEFORE the new members and methods are added.
Additionally (or rather consequently) that very moment, this is of type "class Test" and not of type "class SubTest"

Code:

class Test
{
   
    function test()
    {
        if (this.rawin("fn"))
            print("found");
        else
            print("not found");
    }
}

class SubTest extends Test
{
    function fn()
    {

    }
}

local x=SubTest() ;
x.test() ;  //expected result
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.064 seconds.