[fpc-pascal] Next language feature for pas2js...
Michael Van Canneyt
michael at freepascal.org
Tue May 1 09:03:38 CEST 2018
On Tue, 1 May 2018, Ryan Joseph wrote:
>
>
>> On May 1, 2018, at 11:27 AM, Michalis Kamburelis <michalis.kambi at gmail.com> wrote:
>>
>> I suspect that we will have a unit like WebGL in pas2js that exposes
>> the necessary JS functions for Pascal applications.
>
> Sure but how does the porting process look? I’m reading the wiki and it looks like it wraps JavaScript classes by doing stuff like:
>
> TJSFunction = class external name 'Function'(TJSObject)
>
> where “Function” is the JavaScript class name.
This is actually a less good example, it's a little tricky.
>
> Looking at https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API I see WebGLRenderingContext has the entire OpenGL API (I think). Does that mean we just do something like:
>
> const
> GLfloat = MAP_TO_SOMETHING; // do we have external consts?
Of sorts.
MyClass = Class external name 'my'
const
MyConst : integer
end;
Will emit MyClass.MyConst. The compiler needs to know the type.
>
> type
> TWebGLRenderingContext = class external name 'WebGLRenderingContext' (TJSObject)
> procedure clearColor (red, green, blue, alpha: GLfloat); external name 'clearColor';
> end;
>
> var
> context :
> begin
> context := GetCurrentContext; // document.getElementById(‘canvas’).getContext()
> context.clearColor(0, 0, 0, 0);
That seems about correct.
You don't need the "external name 'n'" if the name is typed correctly.
Michael.
More information about the fpc-pascal
mailing list