Squirrel

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

New slots in class instances?

Last post 11-01-2008, 1:01 AM by Mr. Accident. 2 replies.
Sort Posts: Previous Next
  •  10-10-2008, 5:01 PM 2829

    New slots in class instances?

    I'm using Squirrel 2.1.1. Is it possible to add new slots to an existing instance of a class?

    ie.

    class cFoo
    {
        constructor()
        {
            print("made an instance");
        }
    }

    local fooBar = cFoo();
    fooBar.index <- 1;

    print(fooBar.index);


    This gives me the following error: "AN ERROR HAS OCCURED [indexing instance with string]".

    I know that you can add slots to a class that hasn't been instantiated yet. But can you add slots to an instance of a class?
    If not is it a planned feature?

    I would normally use an extended class, but I need a bit more flexibility than that for what I need to do. I need something somewhere between a table and a class, basically.

    Thanks alot guys.
  •  10-11-2008, 4:00 AM 2830 in reply to 2829

    Re: New slots in class instances?

    Maybe this thread will help you:
    http://squirrel-lang.org/forums/thread/2743.aspx
  •  11-01-2008, 1:01 AM 2859 in reply to 2829

    Re: New slots in class instances?

    This line:

        fooBar.index <- 1;

    should also be throwing an error that says "class instances do not support the new slot operator." Basically, it's specifically disallowed in Squirrel to add new slots to instances of classes. Personally I don't think this restriction is necessary (as you might see from reading my thread that cya linked to), but that's the way Alberto designed the language. :-)
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems