[Pas2js] Re GPU.JS Any suggestions for JavaScript to Pascal Transpilation

warleyalex warleyalex at yahoo.com.br
Sat May 5 15:09:28 CEST 2018


Since the Lazarus IDE understands the concept of the "external classes", so
the code completion / tooling will work! 
----------------
"External Classes": are the glue between the Object Pascal and the
JavaScript world. In fact, as external code is only interfaced – this is not
a real class, but an external class. This means that we only need the
definition while the implementation is done by the external JavaScript code.
So, we can wrap existing javascript libraries transparently and with a
minimum of overhead in pas2js world. Just import a javascript class, one
writes a normal class definition that mimics the Javascript class. 

You can always go deeper with the header translation by looking at the
JavaScript source code, there you can discover whether there are further
overloads to the functions or hidden return values. Also you can spot
fields, which are mostly used internal, but might become useful if you want
to extend the supplied class. It is possible to use properties.

It is important to mention that these classes are case sensitive. This means
that the method "callMe" will become a "callMe" in the JavaScript output.
Alternatively, you can also use any other favorite naming style, but specify
the JavaScript separately. What remains missing are the parameters of the
methods. These can be gathered by taking a closer look at the documentation
for each method.

There's a tool:
--------------
Christian Bunde has started an open source project called ts2pas, you can
find the project here: https://github.com/CWBudde/ts2pas

This ts2pas (it's a NodeJS command line tool to convert the typescript
definition file .d.ts to .pas). A lot of TypeScript definitions can be found
at Definitely Typed (http://definitelytyped.org/). Exactly, you just have to
grab the corresponding typescript definition file .d.ts and use the tool
ts2pas to create the corresponding .pas file. 

This tool it's still far from being perfect. In particular the generated
code does typically not run without manual post processing. It's still not
ready for production use. It's only meant to create a "first draft".
At the moment, it is only possible to convert some selected definitions and
the compiled code might not work in pas2js out of the box. It will be a long
process to make this tool mature enough, it should no so difficult to port
this tool to native pas2js/nodejs project, but it's a good start anyway. 

Regards,
warleyalex



--
Sent from: http://pas2js.38893.n8.nabble.com/


More information about the Pas2js mailing list