YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

[Sqrat] Custom _cmp meta-method for C++ classes.
SLC
#1 Posted : Wednesday, August 24, 2016 3:01:09 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/1/2013(UTC)
Posts: 30
Man
Location: Romania

Thanks: 3 times
Was thanked: 0 time(s) in 0 post(s)
So I register a class from C++ and then I want to overload the _cmp meta-method. However, I can't do that. The function is not present. Neither when I try from script with .newmember() or .rawnewmember() or even with .rawset(). Nothing works. I simply cannot set the _cmp meta-method on classes registered from C++. No error is shown.
absence
#2 Posted : Thursday, August 25, 2016 12:08:45 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 8/23/2014(UTC)
Posts: 109
Man
Location: Northern Germany & Lincolnshire, U.K.

Thanks: 1 times
Was thanked: 10 time(s) in 10 post(s)
sq_pushobject (v, &classdefinition) //this is what sq_newclass leaves on the stack
sq_pushstring(_SC("_cmp"),4) ;
sq_newclosure(v,funcptr,0) ; //funcptr=C-function pointer to your _cmp function
sq_newslot(v,-3,false) ;
sq_poptop(v)


should do. Remember, _cmp will NOT be called for the == operator, only for <, >, <= and >=

(for the == and != operators there is no metamethod, they simply compares the raw values, which in case of instances is the instance (pointer) itself)
SLC
#3 Posted : Friday, August 26, 2016 2:03:20 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 7/1/2013(UTC)
Posts: 30
Man
Location: Romania

Thanks: 3 times
Was thanked: 0 time(s) in 0 post(s)
absence wrote:
Remember, _cmp will NOT be called for the == operator, only for <, >, <= and >=


Pft, then it's quite useless to my current situation.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.129 seconds.