Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function call is not working #183

Open
was547 opened this issue Jul 20, 2019 · 1 comment
Open

Function call is not working #183

was547 opened this issue Jul 20, 2019 · 1 comment

Comments

@was547
Copy link

was547 commented Jul 20, 2019

Hi, I'm trying to call inside lua an C function that contains 2 arguments, but it doesn't works properly, the output give me the error: "error in error handling".

The function have 1 int argument and 1 std::string argument, see:

sel::State lua;
lua.Load(strfmt("../../Scripts/%d.lua", item->PackageId));
lua["SendClientMsg"] = std::function<void(int, std::string)>(SendClientMessage);
int ret = lua["onUse"](m_buffer->Protocol.Connection);

I've tried also in this way:

lua["SendClientMsg"] = &SendClientMessage;

but both ways doesn't work, anyone have a solution to make this work?

the SendClientMessage:

void SendClientMessage(int32_t connectionId, std::string message)

lua file:

function onUse(connId)
    SendClientMessage(connId, "Hello World")
    return 1
end

thanks!

@gtar
Copy link

gtar commented Jun 22, 2020

In your code, sel::State lua doesn't know your function SendClientMsg when you loaded your script.
You shall bind your function first then you can load your script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants