On Tue, 1 May 2018, Ryan Joseph wrote:



On May 1, 2018, at 11:27 AM, Michalis Kamburelis <michalis.ka...@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.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to