QuickJS的LibFFI模块,使用JavaScript调用任意C动态库

QuickJS的LibFFI模块,使用JavaScript调用任意C动态库

https://github.com/shajunxing/quickjs-ffi

例如以下三个C函数,包含在test-lib.so动态库中。

void test1();
double test2(float, double, const char *);
void test3(struct {long; double; struct {int; float} });

在QuickJS下使用该模块的调用范例如下:

import { CFunction } from './quickjs-ffi.js'

let test1 = new CFunction('test-lib.so', 'test1', 'void').invoke;
console.log(test1());

let test2 = new CFunction('test-lib.so', 'test2', 'double', 'float', 'double', 'string').invoke;
console.log(test2(3.141592654, 2.718281829, 'How do you do?'));

let test3 = new CFunction('test-lib.so', 'test3', 'void', ['long', 'double', ['int', 'float']]).invoke;
console.log(test3([123456789, 3.141592654, 54321, 2.718281829]));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值