[fpc-pascal] Next language feature for pas2js...
Michael Van Canneyt
michael at freepascal.org
Tue May 1 10:50:36 CEST 2018
On Tue, 1 May 2018, Ryan Joseph wrote:
>
>
>> On May 1, 2018, at 3:17 PM, Michael Van Canneyt <michael at freepascal.org> wrote:
>>
>>> 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.
>
> Just curious but why can’t you declare a const anywhere for any reasons?
As far as I know, all consts in Javascript are scoped ?
If this is not the case, then of course we should allow it.
>
>>
>>>
>>> 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;
>
> Why do we need to redefine the type if it’s already defined in the JS library? GLfloat isn’t a double also but see my other reply.
You must define the type to something the compiler knows, so the compiler knows what operations it can do.
Imagine:
Type
MyOpaqueType external;
Var
I : MyOpaqueType;
begin
// What can I do with I ? Can I add it ? Can I multiply it ?...
end.
If you really do not know the type, use JSValue. But there is little you can
do with a JSValue except assign or typecast it.
>
> From the link you posted there are these types. Is that even JavaScript? I don’t remember there being typedefs in it or void functions.
The link is a spec. All javascript constructs have such a spec, and they are
a form of IDL, which does specifie types.
>
> interface WebGLActiveInfo
> {
> readonly attribute GLint size;
> readonly attribute GLenum type;
> readonly attribute DOMString name;
> };
>>
>>>
>>> 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?
You are mistaken where that is concerned.
See above: Most APIs _do_ specify a type. You must look it up. Have a look
at the web.pas or js.pas or even libjquery.pas units. Most identifiers have
a type, the use of JSValue is quite limited.
Read-only Attributes can be translated to read-only properties.
The above would be
Type
WebGLActiveInfo = class external name 'WebGLActiveInfo'
Private
fSize : GLint; external name 'size';
ftype: GLEnum; external name 'type';
fName : DOMString ; external name 'name';
Public
Property size : GLInt Read FSize;
Property &type : GLEnum Read fType;
Propert Name : DomString read FName;
end;
Michael.
More information about the fpc-pascal
mailing list