Squirrel

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

Retrieving Class Name

Last post 05-30-2008, 11:45 AM by Capyvara. 1 replies.
Sort Posts: Previous Next
  •  05-26-2008, 10:44 PM 2542

    Retrieving Class Name

    Hi Guys,
    I'm trying to extract the name of the class from an object in squirrel.
    How do I do so without specifying the object's _typeof metamethod?

    class Object
    {
    // Code here
    }

    local obj = Object();
    obj.getclass().name?


  •  05-30-2008, 11:45 AM 2551 in reply to 2542

    Re: Retrieving Class Name

    The class doesn't have a concept of name, when you do a class Object{} you actually create a field named "Object" into the root table which points to the Object class.

    Here are some alternatives:

    class Object
    {
        static ClassName = "Object"
    }

    class Object2 < ClassName = "Object2" >
    {
        function GetClassName()
        {
             return getclass().getattributes().ClassName;
        }
    }


    local obj = Object();
    print(obj.ClassName);

    local obj2 = Object2();
    print(obj2.GetClassName());
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems