[fpc-pascal] Next language feature for pas2js...

Michael Van Canneyt michael at freepascal.org
Tue May 1 11:12:50 CEST 2018



On Tue, 1 May 2018, Ryan Joseph wrote:
>> 
>> 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;
>
> Interface is just a class? That makes sense but “dictionary” is a real type I assume because I know JS has “associative arrays” or hash maps. How do those work in Pascal?

Dictionary is just a TJSObject. The properties are the dictionary.

>
> Shouldn’t there be some automatic tool to parse JS api's to Pascal then? Makes sense so API’s like this can be dumped out easily.

If all you have is the Javascript type of things, then you can dump out the
api, given an instance of an object.

There is a demo project in the SVN which shows how.

But since in Javascript there are no types, the types will be blank.

If you have access to the underlying API spec in the form of an IDL, then we
could make a tool that parses the IDL and dumps the API in the form of
"external" declarations.

Michael.


More information about the fpc-pascal mailing list