Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zy445566/node-c-jit
node.JS run C language Just In Time
https://github.com/zy445566/node-c-jit
c nodejs
Last synced: 5 days ago
JSON representation
node.JS run C language Just In Time
- Host: GitHub
- URL: https://github.com/zy445566/node-c-jit
- Owner: zy445566
- License: mit
- Created: 2017-11-27T01:48:15.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-23T02:05:28.000Z (almost 6 years ago)
- Last Synced: 2024-10-12T17:45:21.419Z (about 1 month ago)
- Topics: c, nodejs
- Language: JavaScript
- Size: 16.6 KB
- Stars: 26
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-c-jit
[![Build Status](https://travis-ci.org/zy445566/node-c-jit.svg?branch=master)](https://travis-ci.org/zy445566/node-c-jit)
node.JS run C language Just In Time# install
-------------------
```sh
npm install c-jit
```# prepare
-------------------
```
npm install node-gyp -g
```
You can see:https://github.com/nodejs/node-gyp#installation# example
-------------------
Grammar reference(NAN example):https://github.com/nodejs/node-addon-examplessync:
```node
const CJit = require("c-jit");
const path = require("path");
let cJit = new CJit();// run by c code sync
let funcByrunSync = cJit.runSync(`
if (info.Length() < 2) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}if (!info[0]->IsNumber() || !info[1]->IsNumber()) {
Nan::ThrowTypeError("Wrong arguments");
return;
}double arg0 = info[0]->NumberValue();
double arg1 = info[1]->NumberValue();
v8::Local num = Nan::New(arg0 + arg1);info.GetReturnValue().Set(num);
`);
console.log("This should be eight(by run sync):"+funcByrunSync(3,5));//run by file sync
let funcByfileSync = cJit.runByFileSync(path.join(__dirname,'test.cc'));
console.log("This should be twelve(by file sync):"+funcByfileSync(6,6));```
async:
```node
const CJit = require("c-jit");
const path = require("path");
let cJit = new CJit();let funcByrun = cJit.run(`
if (info.Length() < 2) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[0]->IsNumber() || !info[1]->IsNumber()) {
Nan::ThrowTypeError("Wrong arguments");
return;
}
double arg0 = info[0]->NumberValue();
double arg1 = info[1]->NumberValue();
v8::Local num = Nan::New(arg0 + arg1);
info.GetReturnValue().Set(num);
`,(err,func)=>{
if (err){console.log(err);return;}
console.log("This should be eight(by run):"+func(3,5));
});// run by file
let funcByfile = cJit.runByFile(path.join(__dirname,'test.cc'),(err,func)=>{
if (err){console.log(err);return;}
console.log("This should be twelve(by file):"+func(6,6));
});```