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

Using SetObjectToPath vs RegisterFunction for assigning C# methods #523

Open
BrianOstrander opened this issue Feb 6, 2024 · 0 comments
Open

Comments

@BrianOstrander
Copy link

Somewhat of an open-ended question, but are there any important performance considerations when choosing between the following ways of assigning C# methods to your lua environment?

Lua lua;
        
void InitializeLua()
{
    lua = new NLua.Lua();
    
    // A
    lua.SetObjectToPath(
        "a",
        (Action)ExampleMethod
    );

    // B
    lua.RegisterFunction(
        "b",
        this,
        GetType()
            .GetMethod(
                nameof(ExampleMethod),
                BindingFlags.NonPublic | BindingFlags.Instance
            )
    );
}

void ExampleMethod()
{
    // Logic
}

I assume they both have their pros and cons, but using method A is more convenient and what I typically lean towards.

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

1 participant