Skip to content

Functions

Kevin Zhao edited this page Jan 25, 2018 · 2 revisions

Functions

Functions can be created using either overload of the CreateFunction method:

var function = lua.CreateFunction(@"
    local x = ...
    return x * x * x");
var function = lua.CreateFunction(new Func<int, int>(x => x * x * x));

These functions can be called using the Call method with a variable number of arguments. The results will be returned in an object array, with an empty object array indicating the lack of any return values.

Dynamic Access

LuaFunctions support dynamic access:

var function = lua.CreateFunction(new Func<int, int>(x => x * x * x));
Assert.Equal(216L, function(6));
Clone this wiki locally