Friday, January 12, 2018

chakracore-delphi initial release

The initial release of chakracore-delphi is out, published under the MIT license.

Short summary:

chakracore-delphi

Delphi and Free Pascal bindings and classes for Microsoft's ChakraCore library.

ChakraCore version: 1.7.6

Supported compilers:

  • Delphi 7 or newer
  • Free Pascal 3.0.4 or newer

Supported target platforms:

  • i386-win32 (Delphi 7 or newer, Free Pascal)
  • x86_64-win64 (Delphi XE2 or newer, Free Pascal)
  • x86_64-linux (Free Pascal)
  • x86_64-darwin (Free Pascal)

Installation:

  1. Clone this repository:
git clone https://github.com/tondrej/chakracore-delphi.git
cd chakracore-delphi
git submodule update --init

or

git clone --recurse-submodules https://github.com/tondrej/chakracore-delphi.git
  1. Download the binaries from the ChakraCore Release page
  2. Enjoy!
view raw README.md hosted with ❤ by GitHub


Comments, ideas and of course pull requests are very welcome. Cheers!

Saturday, January 06, 2018

chakracore-delphi

With the initial release coming up soon, here are a few teaser screenshots of chakracore-delphi, a new opensource library with Delphi and Free Pascal bindings and classes for Microsoft's ChakraCore Javascript engine:


FPC 3.0.4 and Lazarus 1.8 build (win64):

FPC 3.0.4 and Lazarus 1.8 build (linux64):

FPC 3.0.4 and Lazarus 1.8 build (macosx64):

Delphi XE 10.2 Tokyo build (win64):

Delphi 2009 build (win32):

Delphi 7 build (win32):

and a tiny code snippet showing an example of embedding the Javascript engine and exposing some native methods to it:
// example usage...
procedure TDataModuleMain.DataModuleCreate(Sender: TObject);
begin
try
FRuntime := TChakraCoreRuntime.Create([ccroEnableExperimentalFeatures, ccroDispatchSetExceptionsToDebugger]);
FContext := TChakraCoreContext.Create(FRuntime);
FContext.Activate;
ChakraCoreCheck(JsCreateObject(FConsole));
ChakraCoreCheck(JsAddRef(FConsole, nil));
SetCallback(FConsole, 'assert', ConsoleAssertFunc, Self);
SetCallback(FConsole, 'log', ConsoleLogFunc, Self);
SetCallback(FConsole, 'info', ConsoleInfoFunc, Self);
SetCallback(FConsole, 'warn', ConsoleWarnFunc, Self);
SetCallback(FConsole, 'error', ConsoleErrorFunc, Self);
SetCallback(FConsole, 'exception', ConsoleErrorFunc, Self);
SetProperty(FContext.Global, 'console', FConsole);
except
FConsole := nil;
FreeAndNil(FContext);
FreeAndNil(FRuntime);
raise;
end;
end;
procedure TDataModuleMain.DataModuleDestroy(Sender: TObject);
begin
if Assigned(FConsole) then
ChakraCoreCheck(JsRelease(FConsole, nil));
FConsole := nil;
FreeAndNil(FContext);
FreeAndNil(FRuntime);
end;
procedure TDataModuleMain.Execute(const ScriptFileNames: array of UnicodeString);
var
I, Cookie: Integer;
begin
Cookie := 0;
for I := Low(ScriptFileNames) to High(ScriptFileNames) do
begin
RunScript(LoadFile(ScriptFilenames[I]), UnicodeString(ExtractFileName(ScriptFileNames[I])), Cookie);
Inc(Cookie);
end;
end;