Need an example
opened this issue · comments
Hey there. Can you show an example to run some "hello world" easy script? Thanks!
Hi!
Just run ChakraCoreHostSample with a command line parameter specifying the file name of the script to run. For example:
ChakraCoreHostSample hello.js
The script file should contain valid Javascript code, otherwise you'll get runtime errors. Your hello.js
might be as simple as:
console.log("Hello, world!");
The implementation of the console
object is provided by the sample, see Console.pas.
You can write your own Pascal classes and expose them to your scripts in a similar way.
You'll need the Microsoft's ChakraCore shared library (currently at version 1.8.4) available on ChakraCore Release page.
How to install/use the shared library depends on the target operating system:
- On Windows, put it in a directory which is on your system path, or simply in the same directory where your executable is.
- On Linux or OSX, put it in one of the standard library path directories, or use an appropriate environment variable like
LD_LIBRARY_PATH
(Linux) /DYLD_LIBRARY_PATH
(OSX) (see details for Linux, OSX).
What about less code instead of sample app, where will show hello world sample? In current sample too much things that are not helpful.
Hi AlimLetto,
I've added a minimalistic sample in chakracore-delphi/samples/SimpleHostSample/SimpleHost.dpr.
Hope this helps!