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

Sqrat: binding lambda functions to class
JonHodgson
#1 Posted : Wednesday, June 15, 2016 10:40:25 AM(UTC)
Rank: Member

Groups: Registered
Joined: 5/19/2016(UTC)
Posts: 15
Location: UK

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hi,

Is there a way to bind a lambda function to an Sqrat class?

I thought it might be possible using GlobalFunc, but it doesn't seem to work.

Code:
    auto getTagString =    [this](Myclass* my_object) {
        return this->myString;
    };

    table.Bind(_SC("MyClass"), Sqrat::Class<MyClass>(vm, _SC("MyClass"))
        .GlobalFunc(_SC("getStringAttribute"), getStringAttribute) // this works, getStringAttribute is global function
        .GlobalFunc(_SC("getTagString"), getTagString) // this does not work
        );


The reason I wanted to use a lambda rather than a global function is that there is context information required for the function that is specific to the time of binding, and constant from that point onwards. So I don't want to be cluttering up scripts with having to pass that information to the global function.

regards

Jon
JonHodgson
#2 Posted : Monday, June 20, 2016 2:07:13 AM(UTC)
Rank: Member

Groups: Registered
Joined: 5/19/2016(UTC)
Posts: 15
Location: UK

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Once again I'm answering my own question :-)

sqrat can't handle lambdas.

So I've extended it with LambdaFunc methods, which work the same way as GlobalFunc, only with lambdas.

It seems to be working fine, the only downside is that I've had to use boost for some template trickery to get the signature of the lambda to build the right closure for squirrel to call. This isn't an issue for my own projects, because I use boost all over the place, but I would imagine it would be an issue with regards to making this code part of sqrat
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.071 seconds.