jacksondunstan / UnityNativeScripting

Unity Scripting in C++
https://jacksondunstan.com/articles/3938
MIT License
1.34k stars 135 forks source link

Using 2D arrays #63

Closed stonfute closed 4 years ago

stonfute commented 4 years ago

Hi,

I'm using NativeScript in a project and I've notice a problem when using 2D arrays.

In C# I'm defining 2D arrays as float[,] values but this generate System::Array2<System::Single, System::Single> in Bindings.h/cpp

System::Array2<System::Single, System::Single> is not defined and it should generate System::Array2<System::Single>.

Am I right ? Am I using 2D array as designed in generator ? Should I use float[][] instead of float[,] ?

Regards,

jacksondunstan commented 4 years ago

Hi @stonfute ,

float[][] and float[,] are quite different. The former is an array of arrays and may be jagged or even contain null elements. The latter is a 2D array, i.e. one with "rank" 2.

Check out the first and second array articles from the series for more details. The first has a usage example for the config JSON:

{
    "Arrays": [
        {
            "Type": "System.Int32"
        },
        {
            "Type": "System.Single",
            "Ranks": [ 1, 2, 3 ]
        }
    ]
}

In your case, I suspect you should add just this:

{
    "Arrays": [
        {
            "Type": "System.Single",
            "Ranks": [ 2 ]
        }
    ]
}

Hope that helps, -Jackson

stonfute commented 4 years ago

Thank you for your time.

In my case it was "Ranks": [ 1, 2 ] cause I only want to use 2D arrays. I will try.

stonfute commented 4 years ago

This is still an issue with "Ranks": [ 1, 2, 3 ].

Also reproductible with 3D array of any type. C# property with type int[,,] generate System::Array3<System::Int32, System::Int32, System::Int32> type for both get/set methods but it should be System::Array3<System::Int32>

jacksondunstan commented 4 years ago

Hi @stonfute ,

Sorry for closing this issue prematurely; I thought you were just asking a question but now I realize it was a bug report. I've fixed the issue in commit 65e70add52952098c5496ce91c4ef85b00c3895d. Please let me know if the problem persists for you.

Best, -Jackson

stonfute commented 4 years ago

Sorry for closing this issue prematurely; I thought you were just asking a question but now I realize it was a bug report. I've fixed the issue in commit 65e70ad. Please let me know if the problem persists for you.

No problem ! It seams to work like a charm !

Thank you !