Basic introduction to native C modules for QuickJS
I know this engine was created with embedded systems in mind, is really tiny and lightweight, and taking advantage of fact that the code base is still small, I’m trying to understand how it works and mainly, how to extend it.
And that’s what I’m trying to explain here, not form an expert point of view, but a rookie and someone with basic knowledge about C++.
QuickJS is not a kind of NodeJS, it’s more like V8
I’ve seen a lot of confusion about if QuickJS is just a NodeJS replacement, it is not, actually, you can’t port code directly from NodeJS to QuickJS because NodeJS has it’s own APIs (fs, path, process, net, etc) and QuickJS has a very small set of native functions to play with.
What we want at the end of this article is to make this code work in an independent executable after compiling with QuickJS compiler:
Prepare the source
You can read the compiling instructions from https://bellard.org/quickjs/quickjs.html#Installation
After compiling all the source code with
make, try to compile and run the code I described above with:
./qjsc -m -o my_module my_module.js# run