[Pas2js] Records as pure data?

Ryan Joseph ryan at thealchemistguild.com
Wed May 9 16:21:42 CEST 2018



> On May 9, 2018, at 8:46 PM, Michael Van Canneyt <michael at freepascal.org> wrote:
> 
> This will not happen.
> 
> We are transpiling to Javascript. Records translate to javascript object literals and memory layout is opaque.
> The idea is explicitly not to make memory layout available in the language.
> 
> You can use the native constructs that the runtime makes available if you
> need specific memory buffers, but no more than that.

Then what happens with stuff like this? Not sure how to append arrays (didn’t like push for some reason) but I guess we can build arrays like this and then iterate them to build memory buffers?

I know I can just give up and do everything with arrays of floats but it’s worth trying to figure out a better way to do this in advance instead of wasting time down the road trying to construct confusing arrays.

type
	TVec2 = array of single;
	TRGBAb = array of byte;

function V2(x, y: single): TVec2;
begin
	result[0] := x;
	result[1] := y;
end;

function RGBA(r, g, b, a: byte): TRGBAb;
begin
	result[0] := r;
	result[1] := g;
	result[2] := b;
	result[3] := a;
end;

type
	GLTexVertex = record
		pos: TVec2;
		color: TRGBAb;
	end;


var
	v: GLTexVertex;
	verts: array of GLTexVertex;
begin
v.pos := V2(100, 100);
v.color := RGBA(1, 0, 0, 1);
verts.push(v); // gives an error

Regards,
	Ryan Joseph



More information about the Pas2js mailing list