On Tue, 1 May 2018, Ryan Joseph wrote:



On May 1, 2018, at 2:03 PM, Michael Van Canneyt <mich...@freepascal.org> wrote:

Of sorts.
 MyClass = Class external name 'my'
 const
   MyConst : integer
 end;

Will emit MyClass.MyConst. The compiler needs to know the type.

I’m confused now.  The class is named WebGLRenderingContext in JS (I think
that’s what it’s called by JS doesn’t really have classes does it?) so how
does it look?


See below.


// no external name because the names are the same

That is only so for methods and fields. I corrected the class below:

type
  WebGLRenderingContext = class external name 'WebGLRenderingContext'
    procedure clearColor (red, green, blue, alpha: GLfloat);
  end;


So constants must be part of the class? In the example below 
gl.COLOR_BUFFER_BIT is scoped to WebGLRenderingContext so I guess that’s the 
reason.

Yes.

Constants without expression can only exist in an external class.


Also I mistyped, GLfloat is a type so how do this map to JS, or do I even need 
to since the names are the same?

You need to define types.

type
  GLfloat = double;


How does this JS translate to Pascal then? drawingBufferWidth are read only 
properties but no type is specified so how does Pascal handle all the untyped 
variables we see in JS?

This is pascal. You need a type.

https://www.khronos.org/registry/webgl/specs/latest/1.0/

shows that drawingBufferWidth has type GLsizei, which is a long.

If you don't know the type, use JSValue. It's the 'unknown type'. It has
limited possibilities, in essence you'll need to typecast a JSValue before
using it. You can assign JSValues of course.

Michael.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to