سؤال

How do you pass functions from LUA to C++ using Luabridge(1.0.2)

local Callback=function()
    print("Inside Callback function!");
end

And then pass that callback to c++:

self.Background:On("Click",Callback)

the "Click" is const std::string&, but how do you define Callback as a function? I've tried a few approaches (void*,std::function) but none of these work correctly.

هل كانت مفيدة؟

المحلول

Figured it out! If you are trying to pass functions, LuaBridge 2.0 (in development branch) solves this by introducing LuaRef.

Your function would look like this:

void DisplayObject::On( const std::string& Param1,LuaRef Param2 );

then just call the function like so:

Param2();

https://github.com/vinniefalco/LuaBridge/tree/develop

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top