JerryScript Windows/Linux 32/64-bit

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
D.J.Peters
Posts: 7419
Joined: May 28, 2005 3:28

JerryScript Windows/Linux 32/64-bit

Postby D.J.Peters » Mar 29, 2018 18:10

Image
For advanced FreeBASIC users :-)

JerryScript a JavaScript engine for Internet of Things.
Full ECMAScript 5.1 standard compliance.
on github

Why JerryScript ?
I used JavaScript with FreeBASIC at my business more than once in the past.
For this job I compiled SpiderMonkey from Mozilla project for FreeBASIC.
But SpiderMonkey Version 1.8x was the last JavaScript engine with a C interface.
Today SpiderMonkey a part of Firefox has a pure C++ interface only.

How I build JerryScript for FreeBASIC.
Normally you need a Linux box with python installed to compile JerryScript.
How ever I created a code::block project to cross compile JerryScript.
To create "jerryscript.bi" I translated some C include files by hand old-school man :-)

all from: Fri Mar 30, 2018 2:30 pm
download dynamic build: jerryscript.zip
download static build: jerryscript-static.zip
download source code: jerryscript-src.zip

API examples: https://github.com/jerryscript-project/ ... EXAMPLE.md

Joshy
Last edited by D.J.Peters on Mar 30, 2018 15:31, edited 5 times in total.
srvaldez
Posts: 1541
Joined: Sep 25, 2005 21:54

Re: JerryScript Windows/Linux 32/64-bit

Postby srvaldez » Mar 29, 2018 23:14

hello D.J.Peters
what's the minimum version of windows that this would work on? (would it work on Windows 98)?
D.J.Peters
Posts: 7419
Joined: May 28, 2005 3:28

Re: JerryScript Windows/Linux 32/64-bit

Postby D.J.Peters » Mar 30, 2018 1:15

srvaldez wrote:(would it work on Windows 98)?
Why not ?
There isn't any Windows code it's POSIX and C lib.
I can test it only on XP so download and try it out.

But never and I mean NEVER !!!
go online with a running WIN 98 version.

Joshy
srvaldez
Posts: 1541
Joined: Sep 25, 2005 21:54

Re: JerryScript Windows/Linux 32/64-bit

Postby srvaldez » Mar 30, 2018 1:25

D.J.Peters wrote:But never and I mean NEVER !!!
go online with a running WIN 98 version.
Joshy

I am not sure what you meant by that, am guessing that it would not be safe?
in my case it would be run offline, no internet connection.
D.J.Peters
Posts: 7419
Joined: May 28, 2005 3:28

Re: JerryScript Windows/Linux 32/64-bit

Postby D.J.Peters » Mar 30, 2018 5:41

New version published the most important function "jerryx_handler_register_global" was missing in my first build :-(

By the way if you compile POSIX C99 stuff on Windows and Linux -std=C99 isn't the same as -std=gnu99

struct timezone tz;
if I compile with -std=C99 I get an error "size of timezone is unknow" !
I don't know why but If I use -std=gnu99 the error are gone.

How ever I added test02.bas and test03.bas

Joshy

file: test02.bas

Code: Select all

#include once "jerryscript.bi"

'
' main
'
jerry_init(JERRY_INIT_EMPTY)
jerryx_handler_register_global ("print",@jerryx_handler_print)
var script = "print('A String printed with C lib.');"
var code   = jerry_parse(script,len(script),false)
if (not jerry_value_has_error_flag(code)) then
  ' Execute the parsed source code in the Global scope
  var ret_value = jerry_run(code)
  jerry_release_value(ret_value)
end if
jerry_release_value(code)
jerry_cleanup()
sleep

file: test03.bas

Code: Select all

#include once "jerryscript.bi"

function MyNativeStringPrinter cdecl(function_obj_val as const jerry_value_t, _
                                     this_val         as const jerry_value_t, _
                                     args_p           as const jerry_value_t ptr, _
                                     args_cnt         as const jerry_length_t) as jerry_value_t
  if ((args_cnt=1) andalso jerry_value_is_string(args_p[0]))then
    var nChars = jerry_get_string_size(args_p[0])
    dim as zstring ptr buffer = allocate(nChars + 1)
    jerry_string_to_char_buffer(args_p[0], buffer, nChars)
    buffer[nChars] = 0
    print *buffer
    deallocate(buffer)
  end if
  return jerry_create_boolean(true)
end function

'
' main
'
jerry_init(JERRY_INIT_EMPTY)
jerryx_handler_register_global ("printString",@MyNativeStringPrinter)
var script = "printString('A string printed with FreeBASIC');"
var code   = jerry_parse(script,len(script),false)
if (not jerry_value_has_error_flag(code)) then
  ' Execute the parsed source code in the Global scope
  var ret_value = jerry_run(code)
  jerry_release_value(ret_value)
end if
jerry_release_value(code)
jerry_cleanup()
sleep
D.J.Peters
Posts: 7419
Joined: May 28, 2005 3:28

Re: JerryScript Windows/Linux 32/64-bit

Postby D.J.Peters » Mar 30, 2018 13:30

I build a static version of JerryScript also see first post.
No more run-time dependencies :-)

Joshy
srvaldez
Posts: 1541
Joined: Sep 25, 2005 21:54

Re: JerryScript Windows/Linux 32/64-bit

Postby srvaldez » Mar 30, 2018 19:16

thank you D.J.Peters :-)
Iczer
Posts: 37
Joined: Jul 04, 2017 18:09

Re: JerryScript Windows/Linux 32/64-bit

Postby Iczer » Apr 01, 2018 16:19

D.J.Peters
Do you think FB64@JerryScript can compile WanaKana from https://github.com/WaniKani/WanaKana - so I can use use it functions (.toRomaji etc...) in my windows dll?
D.J.Peters
Posts: 7419
Joined: May 28, 2005 3:28

Re: JerryScript Windows/Linux 32/64-bit

Postby D.J.Peters » Apr 01, 2018 17:31

@Iczer JerryScript is a full ECMAScript 5.1 JavaScript compiler and Virtual Machine.
It comes with some predefined objects like Date, Math, JSON ...
If the lib you mean used only this standard objects you can run it with JerryScript.
But often JS libraries used objects from WEB Browser DOM, Window, Canvas ...
you have to implement this missing objects self.

You must be an advanced programmer to do this kind of heavy stuff.

Joshy
Iczer
Posts: 37
Joined: Jul 04, 2017 18:09

Re: JerryScript Windows/Linux 32/64-bit

Postby Iczer » Apr 02, 2018 7:44

Thanks!

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 1 guest