[Pas2js] Multi dimensional static array to dynamic array?
Ryan Joseph
ryan at thealchemistguild.com
Tue May 15 16:59:23 CEST 2018
> On May 15, 2018, at 9:44 PM, Mattias Gaertner <nc-gaertnma at netcologne.de> wrote:
>
> Note: This does not yet work in pas2js.
>
> Theoretically pas2js could translate multi dimensional static arrays to
> a one dimensional array, although that would make the converter more
> complicated. Accessing the sub arrays (e.g. b[1]:=a) would
> require cloning. So it depends on your usage which is better.
>
> Can you use something like this:
>
> TVec3x3 = class external name 'Float32Array' (TJSFloat32Array)
> private
> ...
> public
> property XY[x,y: integer]: Float32 read GetXY write SetXY; default;
> end;
It sounds like what you’re saying is that multidimensional arrays don’t map the same in JS so I shouldn’t be using them. I could have keep the values in a flat array (like above) and indexed them using i = x + y * width but I wanted to avoid that since it’s extra overhead on a low level struct. The temporary solution of copying out to list is much worse so I need to pick my poison perhaps. Varient records/unions are out of the question also as a possible solution.
Regards,
Ryan Joseph
More information about the Pas2js
mailing list