Comments (4)
Or if you have Emscripten installed and add this to scripts
in package.json
:
"emcc-path": "emcc-path",
Then run:
npm run -- node-gyp configure build --asmjs=1
node index.js
It prints the same thing again! (except it doesn't throw the exception, I'll fix this soon).
But now build/Release/nbind.js
(the C++ compiler output) is pure JavaScript and runs in a browser as well!
If possible, it might be a good idea to distribute the asm.js version in your npm package, in case someone installing it is missing Python 2.x or a properly configured C++ compiler. Otherwise, a future nbind version will also allow easily distributing precompiled native binary libraries.
from native-addon-example.
As a bonus, if you add this to scripts
in package.json
:
"ndts": "ndts",
Then run npm run ndts
and it will print:
export class NBindBase { free?(): void }
/** float64_t increment(int32_t); -- Strict */
export function increment(p0: number): number;
/** std::string whoami(); */
export function whoami(): string;
Publishing this with your addon will make TypeScript users happier. Save it as main.d.ts
and add to package.json
:
"types": "main.d.ts"
When publishing the addon on npm, you should also add an index.js
file that exports the C++ API. For example:
module.exports = require('nbind').init(__dirname).lib;
The __dirname
variable tells nbind to initialize the addon provided by the current npm package.
from native-addon-example.
I'm definetly going to look at this library when I have the time, and include it maybe in a next post or this one, I'm not yet sure about that. Thanks a lot for your contribution this lib looks amazing! :)
from native-addon-example.
Thanks! And if the material above is useful, you can use it however you want.
from native-addon-example.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from native-addon-example.