29

尝试Quickjs | 帕奇的手札

 4 years ago
source link: https://uxfeel.com/2019/07/12/20190712-try-quickjs/?
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
b

早上上班看到阮老师这个微博和评论后对Quickjs提起了兴趣。当我点进网站看到Features时,感觉作者是真的牛逼。

Quickjs干了什么?

它能把js构建为二进制可执行文件,能运行至任何地方,也可以基于WASM运行在浏览器上。这是大大地扩展了js的可移植性,在我看来牛逼得不行!

还不单单是这样,对于js还支持ES2019和做了一些数学计算的扩展(支持BigInt, BigFloat), 底层部分对os支持虽然不多但是基本够用,其他细节还有待实现。

下载quickjs-2019-07-09

在MingGW的支持下,Win也能运行。下面例子执行环境在ubuntu16.4

1
2
3
# in linux
cd ./quickjs-2019-07-09
sudo make install

跑完大概是长这样子的:

d

在安装的过程中出现一些问题:

1
2
3
4
5
6
In file included from /usr/include/stdlib.h:24:0,
from qjs.c:25:
/usr/include/features.h:367:25: fatal error: sys/cdefs.h: 没有那个文件或目录
compilation terminated.
Makefile:269: recipe for target '.obj/qjs.m32.o' failed
make: *** [.obj/qjs.m32.o] Error 1

提示出错没有找到sys/cdefs.h文件。

找到原因是缺少c标准库的安装,只需要把库安装了就好了。

1
sudo apt-get install  build-essential libc6-dev libc6-dev-i386

安装后提供4个不同命令:

  • qjs 执行js
  • qjsc 构建js为可执行文件
  • qjsbn 执行js,具有数学扩展的相应解释器和编译器
  • qjsnbc 构建js为可执行文件,具有数学扩展的相应解释器和编译器
1
2
3
4
5
6
qjs examples/hello.js
> Hello World

qjsc -o hello examples/hello.js
./hello
> Hello World

使用的例子还是官方提供的简单例子,至于具体可用的场景及支持还有待调研,Quickjs的实用价值目前还没办法估量。

我这种小弟只能先膜拜一下大神的成果。

如果感兴趣的欢迎在点赞,各个平台累计200赞会考虑深入调研一下可用范围再给大家分享。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK