Run inline C code on the fly.
Version 0.0.9 tested on:
- Linux with nodejs 6.11 64 bit, (gcc 4.8 on x86, gcc 6.3 on ARM)
- Windows 10 with nodejs 6.11 32 and 64 bit
- OSX 10.10 with nodejs 6.10, llvm 3.5 (Cave! TCC is not fully ported to OSX, support is experimental!)
Version 0.1.0 tested on:
- Linux with nodejs 22 & 24 (x86 only)
- inline C functions in JS
- JS callbacks in C
- wchar_t, struct and array support
- async compilation support
See the API documentation.
consttcc=require('node-tinycc');// create a code generatorletgen=tcc.CodeGenerator();// create a compile stateletstate=tcc.DefaultTcc();// declare a C functionletc_func=tcc.c_function('int',// return type'add',// function name in C[['int','a'],['int','b']],// parameters as [type, name]'return a + b + js_func(a, b);'// actual code);gen.addDeclaration(c_func);// add a JS function declaration to Cletjs_func=tcc.c_callable('int',// return type'js_func',// function name in C['int','int'],// parameter types(a,b)=>{returna*b;}// function);gen.addDeclaration(js_func);// compile code and relocatestate.compile(gen.code());state.relocate();// resolve symbols between C and JSgen.bindState(state);// now the C stuff is usableconsole.log(c_func(23,42));// --> prints 1031See demos and tests for more usage examples.