Squirrel

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

[SqPlus] Returning null objects from C++ to Squirrel

Last post 07-01-2008, 3:14 AM by Wahooney. 0 replies.
Sort Posts: Previous Next
  •  07-01-2008, 3:14 AM 2601

    [SqPlus] Returning null objects from C++ to Squirrel

    I've written a function that queries my world for objects that match a certain criteria and then returns one of those objects as a pointer.

    But if my function finds no objects it should return a null value. My C++ function looks like this:
    cObject *cWorld::QueryWorld(cPosition vecQuery)
    {
        cObject *tmp = pObjectList;

        while (tmp)
        {
            if (tmp->rectBounds.Test(vecQuery))
                return tmp;

            tmp = tmp->pNext;
        }

        return 0;
    }


    I've written an binding function:
    cObject *cWorld::bind_QueryWorldPos(cPosition &vecQuery) {return QueryWorld(vecQuery);}

    Then bind it with sqplus:
    SQClassDef<cWorld>(wxT("cWorld"))
        .func(&cWorld::bind_QueryWorldPos, wxT("QueryWorldPos"))
    BindVariable(&scene, wxT("world"));


    Now if I run "::world.QueryWorldPos()" in Squirrel and the function finds no matches it returns an instance when I need it to return null.

    Thanks for any help guys.
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems