neolithos / neolua

A Lua implementation for the Dynamic Language Runtime (DLR).
https://neolua.codeplex.com/
Apache License 2.0
472 stars 76 forks source link

Passing an argument by reference #157

Closed Meigyoku-Thmn closed 1 year ago

Meigyoku-Thmn commented 2 years ago

Does NeoLua support Passing by reference like in C#? I mean:

void ChangeValue(ref int arg) {
    arg = 1;
}

Can this function be implemented in NeoLua, for example:

function ChangeValue(ref arg: int): void
    arg = 1
end

The motivation is that I want to use NeoLua with the Harmony library for game modding.

neolithos commented 2 years ago

No, Lua has multiple return values. if a .net function uses ref parameters, they will be mapped to a result value.

void Test(ref int a);
local r = Test(1);
Meigyoku-Thmn commented 2 years ago

Thanks, guess I have to use DynamicMethod as a wrapper for this functionality.