Squirrel

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

Squirrel does not support authomatic casting? (calling C++ method from squirrel problem).

Last post 08-07-2008, 10:00 AM by hexdump. 2 replies.
Sort Posts: Previous Next
  •  08-06-2008, 3:29 PM 2673

    Squirrel does not support authomatic casting? (calling C++ method from squirrel problem).

    Hi,

    Well I have spent 3 days (around 5 hours) to figure out why I was getting a "not valid parameter" when calling a function from C++ to squirrel.

    My function is pretty simple:

    function InitPlayer(Player)
    {
        Player.SetDexterity            (10.0);
        return Player;
    }

    The fuction gets a pointer to player and sets dexterity on it.

    Important: C++ method from Player was defined as void SetDexterity(float).

    Well the function as it is now works perfectly buy if I change the Player.SetDexterity part to:

    Player.SetDexterity            (10);

    Notice the int parameter I get the error I stated before. Is this ussual operation? should not squirrel cast the int to float?.

    Thanks in advance,
    HexDump.

  •  08-07-2008, 3:09 AM 2674 in reply to 2673

    Re: Squirrel does not support authomatic casting? (calling C++ method from squirrel problem).

    It is SqPlus issue, not Squirrel's

    I recommend you to change in SqPlus.h

    inline bool Match(TypeWrapper<bool>,HSQUIRRELVM v,int idx)           { return sq_gettype(v,idx) == OT_BOOL; }
    inline bool Match(TypeWrapper<char>,HSQUIRRELVM v,int idx)           { return sq_gettype(v,idx) == OT_INTEGER; }
    inline bool Match(TypeWrapper<unsigned char>,HSQUIRRELVM v, int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
    inline bool Match(TypeWrapper<short>,HSQUIRRELVM v,int idx)          { return sq_gettype(v,idx) == OT_INTEGER; }
    inline bool Match(TypeWrapper<unsigned short>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
    inline bool Match(TypeWrapper<int>,HSQUIRRELVM v,int idx)            { return sq_gettype(v,idx) == OT_INTEGER; }
    inline bool Match(TypeWrapper<unsigned int>,HSQUIRRELVM v,int idx)   { return sq_gettype(v,idx) == OT_INTEGER; }
    inline bool Match(TypeWrapper<long>,HSQUIRRELVM v,int idx)           { return sq_gettype(v,idx) == OT_INTEGER; }
    inline bool Match(TypeWrapper<unsigned long>,HSQUIRRELVM v,int idx)  { return sq_gettype(v,idx) == OT_INTEGER; }
    inline bool Match(TypeWrapper<float>,HSQUIRRELVM v,int idx)          { int type = sq_gettype(v,idx); return type == OT_FLOAT; }
    inline bool Match(TypeWrapper<double>,HSQUIRRELVM v,int idx)         { int type = sq_gettype(v,idx); return type == OT_FLOAT; }

    to

    inline bool Match(TypeWrapper<bool>,HSQUIRRELVM v,int idx)           { return sq_gettype(v,idx) & SQOBJECT_CANBEFALSE; }
    inline bool Match(TypeWrapper<signed char>,HSQUIRRELVM v,int idx)    { return sq_gettype(v,idx) == OT_INTEGER; }
    inline bool Match(TypeWrapper<unsigned char>,HSQUIRRELVM v, int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
    inline bool Match(TypeWrapper<short>,HSQUIRRELVM v,int idx)          { return sq_gettype(v,idx) & SQOBJECT_NUMERIC; }
    inline bool Match(TypeWrapper<unsigned short>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) & SQOBJECT_NUMERIC; }
    inline bool Match(TypeWrapper<int>,HSQUIRRELVM v,int idx)            { return sq_gettype(v,idx) & SQOBJECT_NUMERIC; }
    inline bool Match(TypeWrapper<unsigned int>,HSQUIRRELVM v,int idx)   { return sq_gettype(v,idx) & SQOBJECT_NUMERIC; }
    inline bool Match(TypeWrapper<long>,HSQUIRRELVM v,int idx)           { return sq_gettype(v,idx) & SQOBJECT_NUMERIC; }
    inline bool Match(TypeWrapper<unsigned long>,HSQUIRRELVM v,int idx)  { return sq_gettype(v,idx) & SQOBJECT_NUMERIC; }
    inline bool Match(TypeWrapper<float>,HSQUIRRELVM v,int idx)          { return sq_gettype(v,idx) & SQOBJECT_NUMERIC; }
    inline bool Match(TypeWrapper<double>,HSQUIRRELVM v,int idx)         { return sq_gettype(v,idx) & SQOBJECT_NUMERIC; }

  •  08-07-2008, 10:00 AM 2675 in reply to 2674

    Re: Squirrel does not support authomatic casting? (calling C++ method from squirrel problem).

    Thanks mate I will do it.

    HexDump.
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems