Squirrel

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

Overload: strange result

Last post 10-19-2007, 4:54 PM by sentul_sgr. 4 replies.
Sort Posts: Previous Next
  •  10-09-2007, 1:02 PM 2179

    Overload: strange result

    Hi all,

    I'm a newcomer. I'm using SqPlus for binding my c++ code.When binding an overloaded member function, I got a strange result. Here is the c++ code:

    class MyOverload
    {
    public:
        MyOverload() : value(0) {}
        void Inc()    { value++; }
        void Inc(int v)    { value += v; }
        void Dec()   { value--; }
        void Dec(int v) { value -= v; }
        void Mult(int v)   { value *= v; }
        int value;
    };
    DECLARE_INSTANCE_TYPE(MyOverload)

    Binding using SQClassDef:

    SQClassDef<MyOverload>(_T("MyOverload"))
            .var(&MyOverload::value, _T("value"))
            .overloadFunc<void (MyOverload::*)(void)>(&MyOverload::Dec, _T("Dec"))
            .overloadFunc<void (MyOverload::*)(int)>(&MyOverload::Dec, _T("Dec"))
            .overloadFunc<void (MyOverload::*)(void)>(&MyOverload::Inc, _T("Inc"))
            .overloadFunc<void (MyOverload::*)(int)>(&MyOverload::Inc, _T("Inc"))
            .func(&MyOverload::Mult, _T("Mult")) ;

    Squirrel test script:

    local ov = MyOverload();
    print("Initial Value:" + ov.value);
    ov.Inc();
    print("Value after Inc:" + ov.value);
    ov.Inc(10);
    print("Value(10):" + ov.value);
    ov.Dec();
    print("Value after Dec:" + ov.value);
    ov.Dec(30);
    print("Value(30):" + ov.value);
    ov.Mult(10);
    print("Value after Mult(10)" + ov.value);

    Result:

    Initial Value:0
    Value after Inc:1
    Value(10):11
    Value after Dec:12
    Value(30):42
    Value after Mult(10)420

    It seems that the if the member function has same type of argument(s), the latest function will be called. I've changed binding order(Inc followed by Dec) and I got an opposite result.

    Any suggestions?

     

     

     

     

  •  10-10-2007, 6:04 AM 2182 in reply to 2179

    Re: Overload: strange result

    Thank you for you report.
    Yes, it's a bug of overloading support of sqplus.  I'm working on it in another thread.

    I will be happy if you would test the fixed code on the SVN.
    Please get it from svn repository: https://sqplus.svn.sourceforge.net/svnroot/sqplus/branches/tegan-r119-overloadconst

    Anyway the fix will be included in the next snapshot of sqplus.

    Regards,
    K. Kawachi
  •  10-11-2007, 9:40 PM 2185 in reply to 2182

    Re: Overload: strange result

    Thank you,
    I've download the SVN codes. Now I'm getting correct results. Great jobs, keep going.

    BTW, I have another questions.
    1. Any idea how to bind a function (global or member functions) that has a pointer as its argument(s), e.g. myfunc(int *, float *).
    2. Is that possible to bind functions with variable arguments, like printf ?
    3. How to bind a constant that is a pointer? e.g. Color * gBLACK?

    Thank you in advance.
  •  10-14-2007, 7:32 AM 2194 in reply to 2185

    Re: Overload: strange result

    The fix is now released as a snapshot: SQUIRREL2_1_1_sqplus_snapshot_20071014.zip

    > 2. Is that possible to bind functions with variable arguments, like printf ?

    Please see "testSqPlus2unit/test_GlobalFunctionBindings.cpp"

    > 1. Any idea how to bind a function (global or member functions)
    > that has a pointer as its argument(s), e.g. myfunc(int *, float *).
    > 3. How to bind a constant that is a pointer? e.g. Color * gBLACK?

    Basically it can be written as the same way of binding reference in test_ObjectGetSet.cpp,
    but at this point some declaration for int * or const pointer seem to be missing in sqplus.h.

    Any ideas?

    K. Kawachi

  •  10-19-2007, 4:54 PM 2213 in reply to 2194

    Re: Overload: strange result

    Thank you for you suggestions,
    Actually I've tried to bind using BindVariable with argument
    VAR_ACCESS_CONSTANT. Binding it self was successfully done,
    but when accessing from squirrel script, the content was modified.
    e.g:
    local color = gBLACK;
    color = gWHITE;
    after writing to the variable, now gBLACK became gWHITE.
    Now I solved the problem simply by change the BindVariable attribute to
    VAR_ACCESS_READ_ONLY. It works fine.


    I've just begun to using sqplus, and I really appreciate your works and your help.
    I'll search trough the sqplus code(s) to understand the mechanism.

    regards.


     

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