Squirrel

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

How to use sq_newtable?

Last post 07-30-2008, 11:30 AM by cya. 4 replies.
Sort Posts: Previous Next
  •  07-29-2008, 8:43 AM 2657

    How to use sq_newtable?

    Hi, I'm new to squirrel and ran into some problems.
    As the tile says: How do I use it?

    Here is some sample code:

    void register_entity(HSQUIRRELVM v)
    {
        sq_pushroottable(v); //on stack 1

        sq_pushstring(v, "numbers", -1); //2
        sq_newtable(v); //3

            // one
            sq_pushstring(v, "one", -1); //4
            sq_pushinteger(v, 1);//5
            sq_newslot(v, -3, SQFalse );//3

            // two
            sq_pushstring(v, "two", -1);
            sq_pushinteger(v, 2);
            sq_newslot(v, -3, SQFalse );

            // three
            sq_pushstring(v, "three", -1);
            sq_pushinteger(v, 3);
            sq_newslot(v, -3, SQFalse );

        sq_newslot(v, -3, SQFalse );//1

        sq_pushstring(v, _SC("Entity"), -1);//2
        sq_newclass(v, SQFalse);//3
        sq_settypetag(v, -1, reinterpret_cast<SQUserPointer>(SQ_ENTITY_TYPE_TAG));

        for (SQInteger i = 0; entity_funcsIdea [I].name != 0; ++i)
        {
            SQRegFunction &f = entity_funcsIdea [I];

            sq_pushstring(v, f.name, -1);//4
            sq_newclosure(v, f.f, 0);//5
            sq_setparamscheck(v, f.nparamscheck, f.typemask);
            sq_setnativeclosurename(v, -1, f.name);
            sq_newslot(v, -3, SQFalse);//3
        }

        sq_newslot(v,-3, SQFalse);//1

        sq_pop(v, 1);// pop the root table 0
    }

    I can create 'Entity' instances but not access the 'numbers table ([the index 'numbers' does not exist]). I'm using the Squirrel 3.0 alpha.
  •  07-29-2008, 2:16 PM 2658 in reply to 2657

    Re: How to use sq_newtable?

    I think that is everything ok, I tried on my sandbox here and I can access normally the numbers table, check out if you aren't nulling the field "numbers" in another place.
  •  07-29-2008, 11:42 PM 2661 in reply to 2658

    Re: How to use sq_newtable?

    Hi, thanks that you tired it. It turned out to be something completely different.
    It seems to have something to do with my IDE. If I start the application outside the IDE, everything runs, even if the IDE points at the same executable. Investigation of this issue is still ongoing...Weird!
  •  07-30-2008, 11:16 AM 2663 in reply to 2661

    Re: How to use sq_newtable?

    Check out for the working directory, also, when debbuging some debuggers initialize variables to different patterns to help debugging, check if you aren't forgetting to initialize some variables.
  •  07-30-2008, 11:30 AM 2664 in reply to 2657

    Re: How to use sq_newtable?

    It works now. I don't know what caused it, though, since I did not change any settings...
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems