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

AGS 4 / New compiler: regular arrays of dynamic arrays #2080

Closed
ivan-mogilko opened this issue Aug 8, 2023 · 5 comments
Closed

AGS 4 / New compiler: regular arrays of dynamic arrays #2080

ivan-mogilko opened this issue Aug 8, 2023 · 5 comments
Labels
ags 4 related to the ags4 development context: script compiler type: enhancement a suggestion or necessity to have something improved

Comments

@ivan-mogilko
Copy link
Contributor

ivan-mogilko commented Aug 8, 2023

I might have missed something, but it seems there's no way to have a regular array storing pointers to dynamic array inside.
I cannot think of reasons why this would not be possible (because regular arrays of pointers are supported), so likely it's a lack of script syntax.

Things I tried:

Character*[] arr1[10];
Character[] arr2[10];
Character* arr3[10][];
Character arr4[10][];

none of the above worked.

Hence my proposal is to support regular arrays of dynamic arrays. Honestly, I am unsure of what the correct syntax should be.

See Also: #1258

Existing workaround

The workaround is to make a struct (or managed struct) with dynamic array inside, although that creates an extra type and extra level of indirection:

struct Array {
    int a[];
};

Array a[10];

Unfortunately, dynamic arrays of dynamic arrays are also impossible at the moment, see #1258.

@ivan-mogilko ivan-mogilko added type: enhancement a suggestion or necessity to have something improved ags 4 related to the ags4 development context: script compiler labels Aug 8, 2023
@ivan-mogilko ivan-mogilko added this to the 4.0.0 (preliminary) milestone Aug 8, 2023
@ivan-mogilko ivan-mogilko changed the title New compiler: arrays of dynamic arrays AGS 4 / New compiler: regular arrays of dynamic arrays Aug 8, 2023
@fernewelten
Copy link
Contributor

I think it should be possible. I'll look into this and see why the compiler doesn't like it.

@ivan-mogilko
Copy link
Contributor Author

ivan-mogilko commented Aug 15, 2023

@fernewelten if you get more spare time afterwards, would you also be able to look if #1818 (dynamic arrays of regular structs) is easy enough to accomplish? I imagine that in the best case this is a matter of checking the element kind (regular/managed), and choose between directly accessing array memory with offset, or dereferencing a managed pointer and accessing its element.

@fernewelten
Copy link
Contributor

Will do!

@fernewelten
Copy link
Contributor

Addressed in #2106.

@ivan-mogilko
Copy link
Contributor Author

Implemented by #2106.

The syntax is e.g.:

int arr1[5][][];
Character* arr2[10][];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ags 4 related to the ags4 development context: script compiler type: enhancement a suggestion or necessity to have something improved
Projects
None yet
Development

No branches or pull requests

2 participants