Re: Adding Javascript to Pascal

Mattias Gaertner via fpc-pascal <[email protected]>
Newsgroups gmane.comp.compilers.free-pascal.general
Message-ID <[email protected]>

On 2/21/25 12:04, Anthony Walter via fpc-pascal wrote:
>[...]
> Javascript:
> 
> let data = { name: "James", age: 25 };
> 
> function update(name) {
>    data.name = name;
> }
> 
> function verify(note) {
>    console.log("received note " + note);
>    console.log("data name is " + data.name);
>    hello(data, " message from javascript");
>    console.log("table size is " + table.size[0] + " by " + table.size[1]);
> }
> 
> Pascal:
> 
> function JavascriptCallback(Script: IScript; Args: TScriptValues):
> TScriptValue;
> begin
>    WriteLn(Args[0].age, Args[1]);



>    // writes 25 message from javascript
>    Result := Nothing;
> end;
> 
> var
>    TestScript: IJavascript;
> 
> procedure LoadScript;
> begin
>     Script := NewScript(MyScriptText);
>     Script.Global.table.size := [15, 6];
>     // { table: { size: [15, 6] } } is now available to javascript

Here I see one big problem.
Pascal needs specific types at compile-time.
JS at compile time can only check some basic syntax. An IDE can use some 
heuristic to guess, what an identifier is referring to, but how should 
that work with a compiler?



>     Script.Global.hello := Script.DefineCallback(JavascriptCallback);
> end;
> 
> procedure CallScript;
> begin
>    // Call the javascript verify method passing it a note
>    Script.Global.verify("a note from pascal");
>    // verify will call back out JavascriptCallback function
>    Script.Global.update("Ralph");
> end;

Mattias

_______________________________________________
fpc-pascal maillist  -  [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.