moonsharp
moonsharp copied to clipboard
[Help] Doubt about using a moon function as a parameter
how do I pass a moon function as a parameter :?
I'm trying with
--lua
function ButtonDown ()
print ('tste')
end
core.creator_button ("Abacatao ITEM", ButtonDown, "print ('test')", "Deck")
C#
Environment.Call(LuaExecuteButtonDown);
I want to pass this function as a parameter, store it in a variable and execute it later. It's possible?
You can get the function using script.Globals.Get(functionName)
where script
is your Lua Script instance from MoonSharp. It will return a DynValue. Then just execute it using script.Call(fn)
.
If you want to store a c# method call to execute later there's plenty of ways, perhaps one of the simplest is to store it as an Action:
Action myFunctionCall = () => Environment.Call(LuaExecuteButtonDown);
// ...
myFunction.Invoke();