neolithos / neolua

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

Functions + arrays = issues ? #129

Closed jesusgumbau closed 2 years ago

jesusgumbau commented 3 years ago

NeoLua Version: 1.3.13

I am having a weird issue returning arrays from functions:

On the C# side I declare 2 functions:

env.func1 = new Func<T1[]>(() => { /* return array with some elements of type T1 */ });
env.func2 = new Func<T1[], T2[]>((a1) => { /* process array T1 and return array T2 */ });

The problem is that the following code will work fine:

local a = func1(); local b = func2(a);

But this will fail with an internal exception (trying to convert from T1[] to T1)

local b = func2(func1());

Any ideas?

neolithos commented 3 years ago

This should also work:

local b = func2((func1()));

It is a conflict, between c# has only one return value and lua can support multiple return values.

I have currently no final solution. Because, if change something on one, something else will break.

jesusgumbau commented 3 years ago

Ok, I was thinking it had to do with Lua being able to return multiple values.

At least we can use the form you proposed.

Thanks.

neolithos commented 3 years ago

(x) returns only the first value of the return set. If you have a function with multiple arguments like func2(func1(), 12), you do not need the ().