Skip to content

Conversation

@CatchABus
Copy link
Contributor

@CatchABus CatchABus commented Oct 26, 2025

This PR adds functionality for creating a Reference array of structs to fill a pointer with. e.g.

        const structs = [
            new TNSSimpleStruct({x: 1, y: 2}),
            new TNSSimpleStruct({x: 3, y: 4}),
            new TNSSimpleStruct({x: 5, y: 6})
        ];
        const length = structs.length;
        const ptr = interop.alloc(interop.sizeof(TNSSimpleStruct) * length);

        const ref = new interop.Reference(TNSSimpleStruct, ptr);
        for (let i = 0; i < length; i++) {
            ref[i] = structs[i];
        }

We are still missing handling for objc classes but I think this is a good starting point.
Fixes/Closes #86 #134

@CatchABus CatchABus marked this pull request as ready for review October 26, 2025 23:06
@NathanWalker NathanWalker added this to the 9.0 milestone Oct 26, 2025
@CatchABus CatchABus marked this pull request as draft October 27, 2025 17:33
@CatchABus CatchABus marked this pull request as ready for review October 28, 2025 14:29
@CatchABus
Copy link
Contributor Author

CatchABus commented Oct 28, 2025

I post a bit of information here regarding the additions in this PR.
By default, runtime converts pointers to Reference of value instances before exposing them as properties or arguments.
During this conversion, the runtime loses track of indexed values.
This commit comes into play to solve this: a91e316
With this, we create a Reference of pointer instance which maintains current functionality AND the indexed values but the exposed reference has still no type to allow index access.

To make up for this limitation, users will have to expose the pointer and create a new typed Reference based on it
e.g.

This is more apparent in the corresponding tests: 6ac6728#diff-8f0ec460aa520af85271ca534d06a7e109efc827e6911b1757100e483bb38b82

UPDATED: The following commit makes index access functional for pointer References without type if already populated:
625bb0e

@NathanWalker NathanWalker merged commit d289232 into NativeScript:main Nov 1, 2025
3 checks passed
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

Successfully merging this pull request may close these issues.

interop.Reference to Array crashes App

2 participants