Skip to content

std::function and self #90

@joeroback

Description

@joeroback

I have a callback that get's bound in lua and from c++ I'd like to invoke that, but self is always nil and I am not sure how to access self as the lua table, not the Client* C++ object...

local client = require 'client'
local view = {}

function view:onConnect()
  self.connected = true
end

function view:create()
  client:onConnect(self.onConnect)
end
m["Client"].setClass(
    UserdataMetatable<Client>()
        .addStaticFunction("onConnect", [](Client* self, const std::function<void(void)>& connectFn)
        {
            connectFn();
        })
);

Is this possible with kaguya?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions