Forum > Pas2JS
Pas2js, typed arrays and ANSI strings
(1/1)
Kryvich:
Hi,
Can Pas2js transpile Delphi/FPC typed arrays to their counterparts in JavaScript? I mean
* array of Integer -> Int32Array
* array of Byte -> UInt8Array
* array of Word -> UInt16Array
* etc.I see declarations of TJSInt32Array, TJSUint8Array, TJSUint16Array in js.pas, but when I try to transpile my test program I can't find these names in the result JS file.
If/when these arrays will be supported by the transpiler, we can move further and try to convert AnsiStrings as UInt8Array.
Kryvich:
OK I can use JavaScript typed arrays using bindings from js.pas!
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program TestTypedArrays;{$IFDEF PAS2JS}uses JS;{$ENDIF} type{$IFDEF PAS2JS} TByteArray = TJSUint8Array; TWordArray = TJSUint16Array;{$ELSE} TByteArray = array of Byte; TWordArray = array of Word;{$ENDIF} procedure Test;var ba: TByteArray; wa: TWordArray;begin{$IFDEF PAS2JS} ba := TByteArray.new(10);{$ELSE} SetLength(ba, 10);{$ENDIF} ba[0] := $FF;{$IFDEF PAS2JS} wa := TWordArray.new(20);{$ELSE} SetLength(wa, 20);{$ENDIF} wa[1] := $FFEE; Writeln('ba[0] = ', ba[0], ', wa[1] = ', wa[1]);end; begin Test;end.
But there is too much IFDEFs. Would be nice to have the same syntax as in Delphi/FPC.
mattias:
At the moment all dynamic arrays are TJSArrays.
Using the typed arrays is an interesting proposal.
Navigation
[0] Message Index