Recent

Author Topic: Trying to learn how to use DelphiDuktape with Lazarus  (Read 615 times)

vico

  • Newbie
  • Posts: 4
Trying to learn how to use DelphiDuktape with Lazarus
« on: March 26, 2021, 03:43:36 am »
So i've downloaded DelphiDuktape to try to play again with Pascal/Lazarus. So i've created a new Lazarus (v2.0.10) Program (windowed) and put Duktape.Api.pas, Duktape.Glue.pas, Duktape.pas and Grijjy.inc into my project folder, alongside the .dlls on Bin.

I just added the includes on `uses`, my code for Unit1.pas is exactly this:..

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Duktape.Api in 'Duktape.Api.pas',
  9.   Duktape in 'Duktape.pas';;
  10.  
  11. type
  12.  
  13.   { TfrmPrincipal }
  14.  
  15.   TfrmPrincipal = class(TForm)
  16.     memConsole: TMemo;
  17.   private
  18.  
  19.   public
  20.  
  21.   end;
  22.  
  23. var
  24.   frmPrincipal: TfrmPrincipal;
  25.  
  26. implementation
  27.  
  28. {$R *.lfm}
  29.  
  30. end.
  31.  

...but when i try to compile and run the project i get this error:

Duktape.pas(10,3) Fatal: Unable to find System.SysUtils used by Duktape. (the message here can sounds weird because my Lazarus is set to Portuguese and i tried to translate the error to English for better understanding).

Going to Duktape.pas and changing System.SysUtils to just SysUtils suppress this warning, but trying to run again i got this other error:

Duktape.pas(28,5) Fatal: Syntax error, ":" expected but "identifier _DATA" found

So, what i'm doing wrong here? I'm missing something? Or is just this project which isn't compatible with FreePascal / Lazarus?

Thanks in advance for any help!
« Last Edit: March 26, 2021, 03:45:16 am by vico »

engkin

  • Hero Member
  • *****
  • Posts: 2704
Re: Trying to learn how to use DelphiDuktape with Lazarus
« Reply #1 on: March 26, 2021, 03:57:10 am »
It is not ported to FPC, try making mode delphi the default by adding -Mdelphi to the "Custom Options" of the project.

On the other hand there is JS engine in Pascal by BeRo, if that's what you want.
« Last Edit: March 26, 2021, 04:31:36 am by engkin »

vico

  • Newbie
  • Posts: 4
Re: Trying to learn how to use DelphiDuktape with Lazarus
« Reply #2 on: March 26, 2021, 04:07:17 am »
It is not ported to FPC, try making mode delphi the default by adding -Mdelohi to the "Custom Options" of the project.

Tried adding the flag, System.SysUtils still gives me error, and replacing by just SysUtils now redirects me for another error related to this line:

Code: Pascal  [Select][+][-]
  1. class function TDuktape.Create(const AUseDelphiMemoryManager: Boolean): TDuktape;
  2. begin
  3.   if (AUseDelphiMemoryManager) then
  4.     Result.FContext := duk_create_heap(DelphiAlloc, DelphiRealloc, DelphiFree, nil, FatalHandler)
  5.   else
  6.     Result.FContext := duk_create_heap(nil, nil, nil, nil, FatalHandler);
  7.  
  8.   if (Result.FContext = nil) then
  9.     raise EdtError.Create('Unable to create Duktape heap and context');
  10. end;    
  11.  

Seems like all Delphi<something> variables like DelphiAlloc didn't exist on FreePascal/Lazarus and refuses to compile.


On the other hand there is JS engine in Pascal by BeRo, if that's what you want.

Didn't knew about that. I was tempting to use DelphiDuktape because i like Duktape (seems to be very tiny and efficient natively) and the tutorial provided by its git repository to how embed it is very intuitive (in fact it offers three ways to embed the engine to a Pascal project, two with near-native efficienty and other slighty slower).

engkin

  • Hero Member
  • *****
  • Posts: 2704
Re: Trying to learn how to use DelphiDuktape with Lazarus
« Reply #3 on: March 26, 2021, 04:29:53 am »
Here is the link:
https://github.com/BeRo1985/besen

I had tried it previously with HTMLViewer.
« Last Edit: March 26, 2021, 04:32:16 am by engkin »

vico

  • Newbie
  • Posts: 4
Re: Trying to learn how to use DelphiDuktape with Lazarus
« Reply #4 on: March 28, 2021, 01:36:55 am »
Here is the link:
https://github.com/BeRo1985/besen

I had tried it previously with HTMLViewer.

Thanks for the suggestion or besen, but i didn't understood how could i use that. I'm still kinda newbie in Pascal, and i was looking to Duktape because for me its more intuitive to set up.

engkin

  • Hero Member
  • *****
  • Posts: 2704
Re: Trying to learn how to use DelphiDuktape with Lazarus
« Reply #5 on: March 28, 2021, 08:42:37 pm »
There is a JS "shell" application included. It shows how to:
1-Create an instance of TBESEN
2-Register functions,  like "version()"
3-Create TBESENObject to represent "document", "window", or "navigator"
4-How to register functions to these objects, like "document.writeln()".
5-How to register properties to these objects, like "navigator.userAgent".

Simply read the code and see how it works, and if you questions come back and ask. But if you are starting with Pascal, it is more logical to build enough confidence and skill in it first.

 

TinyPortal © 2005-2018