Squirrel

The programming language
Welcome to Squirrel Sign in | Join | Help
in Search

Querying Class Hierarchy

Last post 10-22-2007, 10:26 AM by juggernaut. 2 replies.
Sort Posts: Previous Next
  •  11-11-2005, 3:50 AM 428

    Querying Class Hierarchy

    My current project is using Squirrel as it's scripting langauge.  As part of its UI, there is a windows treeview control which I wish to populate with the class hierarchy which is definded in Squirrel scripts. 

    Unfortunately, I can walk to root table to get all the defined classes but I cant manage to find out a Class's base class.  Is there an API function that I could use to get a class's base class?  I've checked the documentation and I cant seem to find what Im after.   Ive tried also tried using the "pseudo slot" parent but that does not seem to work from the C API.

    Thanks in advance.
  •  11-11-2005, 5:44 AM 430 in reply to 428

    Re: Querying Class Hierarchy

    You are right, this is actually sort of a bug(in my head) I forgot to expose this feature in the api.

    It will be in the next realease in this form

    SQRESULT sq_getbase(HSQUIRRELVM v,SQInteger idx)
    {
     SQObjectPtr *o = NULL;
     _GETSAFE_OBJ(v, idx, OT_CLASS,o);
     if(_class(*o)->_base)
      v->Push(SQObjectPtr(_class(*o)->_base));
     else
      v->Push(_null_);
     return SQ_OK;
    }

    you can paste this in sqapi.cpp

    ciao

    Alberto

  •  10-22-2007, 10:26 AM 2222 in reply to 430

    Re: Querying Class Hierarchy

    Does a SqPlus wrapper exist for this functionality? I searched the codebase, but didn't find anything.

    To add, put this in SquirrelObject.h public section of class SquirrelObject:

    public:
        SquirrelObject GetBase();


    And put the definition somewhere in SquirrelObject.cpp:

    SquirrelObject SquirrelObject::GetBase(void)
    {
       SquirrelObject ret;
       sq_pushobject(SquirrelVM::_VM,_o);
       sq_getbase(SquirrelVM::_VM,-1);
       ret.AttachToStackObject(-1);
       sq_pop(SquirrelVM::_VM,2);

       return ret;
    }


    Please test this out, and add corrections if necessary. It would be nice if this could make it into SqPlus somehow.
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems