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

Issue generating _get/_set metamethods for class
gage
#1 Posted : Thursday, November 04, 2010 3:38:48 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 11/4/2010(UTC)
Posts: 30

Thanks: 0 times
Was thanked: 1 time(s) in 1 post(s)
Im embedding Squirrel into a project and am having an issue. Ive had good luck with it to this point engaging native methods and the like, but I wish to allow binding properties from C++ on the squirrel end. Im able to overload _set okay but _get is causing major headaches.

My squirrel class in question is here:
Code:
class Console extends Object
{
    OnLogUpdated = null;
    
    constructor()
    {
        Object.constructor();
        OnLogUpdated = ConsoleEventDelegate();
        
        echo("Console initialized");
    }
}


If I add a _get native closure to this class, it will invoke asking me for the location of "Object" ??? and then fail because it can't find the constructor identifier. I'm registering _get with the class before I instance it so I dont think that would be a problem but that appears to be false. Any help would be greatly appreciated.

for the record the code i wrote to bind the closures looks like so:
Code:

int fulltop = sq_gettop( mVM );

    sq_pushroottable( mVM );
    sq_pushstring( mVM, _SC(klass->getClassname()), -1 ); //would be "Console"
    sq_get( mVM, -2 );

    //register property get/set
    sq_pushstring( mVM, _SC("_set"), -1 );
    sq_newclosure( mVM, scriptOnObjectSet, 0 );
    sq_newslot( mVM, -3, SQFalse );

    sq_pushstring( mVM, _SC("_get"), -1 );
    sq_newclosure( mVM, scriptOnObjectGet, 0 );
    sq_newslot( mVM, -3, SQFalse );

    sq_settop( mVM, fulltop );
fagiano
#2 Posted : Thursday, November 04, 2010 9:08:25 AM(UTC)
Rank: Advanced Member

Groups: Registered, Administrators
Joined: 6/11/2005(UTC)
Posts: 827

Thanks: 0 times
Was thanked: 36 time(s) in 29 post(s)
The fact that it asks for "Object" is normal, is trying to evaluate "Object.constructor();" to avoid that you should write "::Object.constructor();"
The VM tries this.Object, if it fails it fallsback to the root "::Object".

If you are using Squirrel 3.x just "throw null" for any index that you don't recognize. For 2.x you can just throw any error.

ciao
Alberto
gage
#3 Posted : Thursday, November 04, 2010 7:26:52 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 11/4/2010(UTC)
Posts: 30

Thanks: 0 times
Was thanked: 1 time(s) in 1 post(s)
that worked great, thanks for setting me straight. For the record I'm using Squirrel 2. Hows progress going on 3?
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.099 seconds.