• Popular Now

• 12
• 12
• 9
• 10
• 13

This topic is 2750 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I needed to be able to register increment operators for some of my classes, so I added support for this to angelscript. I named the operator functions opPreInc, opPreDec, opPostDec & opPostInc. It works for both script and application classes.

If I recall you prefer the full file so you can run a diff on it, you can get it at http://home.comcast.net/~jeremyh/as_compiler.cpp. The file is from the latest revision (676).

Thanks,
Jeremy

Share on other sites
Forgot to mention that I think it should throw a error if you try to use this on a const object or handle, for example this will work:

class Test {    int num;    Test() {        num = 0;    }    void opPreInc() {        print(++num);    }    void opPostInc() {        print(num++);    }}void main() {    const Test t;    const Test @h = t;    h++;}

So this needs to be fixed, if I get some time when I get home from work I will try to fix it.

This will not work:
class Test {    int num;    Test() {        num = 0;    }    void opPreInc() {        print(++num);    }    void opPostInc() {        print(num++);    }}void main() {    const Test t;    t++;}

You will just get " Reference is read-only" which is correct.

Share on other sites
Thanks. I'll take a look at this.

Share on other sites
I think the following correctly fixes it:
if( isConst ){    Error(TXT_NON_CONST_METHOD_ON_CONST_OBJ, node);    return -1;}

I've uploaded the new copy at http://home.comcast.net/~jeremyh/new-as_compiler.cpp.

Share on other sites
I've added this to the library in revision 687. My implementation is different though, as I reused the code I already had for the unary operators opNeg (-) and opCom (~). Let me know if you find any problems with it.

Thanks for the contribution.