@@ -362,20 +362,18 @@ Implement a C API in JavaScript
362
362
It is possible to implement a C API in JavaScript! This is the approach
363
363
used in many of Emscripten's libraries, like SDL1 and OpenGL.
364
364
365
- You can use it to write your own APIs to call from C/C++. To do this
366
- you define the interface, decorating with ``extern `` to mark the methods
367
- in the API as external symbols. You then implement the symbols in
368
- JavaScript by simply adding their definition to `library.js `_ (by
369
- default). When compiling the C code, the compiler looks in the JavaScript
370
- libraries for relevant external symbols.
371
-
372
- By default, the implementation is added to **library.js ** (and this is
373
- where you'll find parts of Emscripten's *libc *). You can put
374
- the JavaScript implementation in your own library file and add it using
375
- the :ref: `emcc option <emcc-js-library >` ``--js-library ``. See
376
- `test_jslib `_ in **test/test_other.py ** for a complete working
377
- example, including the syntax you should use inside the JavaScript library
378
- file.
365
+ You can use it to write your own APIs to call from C/C++. To do this you define
366
+ the interface, decorating with ``extern `` to mark the methods in the API as
367
+ external symbols. You can them implement the symbols in JavaScript by simply
368
+ adding their definition to one of the `core JS library `_ files. Undefined
369
+ native symbols will be resolved by looking for them in JavaScript library files.
370
+
371
+ The `core JS library `_ files are where you will find Emscripten internals. For
372
+ example, parts of Emscripten's *libc * are implemented there. You can also put
373
+ the JavaScript implementation in your own library file and add it using the
374
+ :ref: `emcc option <emcc-js-library >` ``--js-library ``. See `test_jslib `_ in
375
+ **test/test_other.py ** for a complete working example, including the syntax you
376
+ should use inside the JavaScript library file.
379
377
380
378
As a simple example, consider the case where you have some C code like this:
381
379
@@ -843,8 +841,8 @@ on Emscripten. If you would like to port existing Node-API addon to WebAssembly
843
841
or compile the same binding code to both Node.js native addon and WebAssembly,
844
842
you can give it a try. See `Emnapi documentation `_ for more details.
845
843
846
- .. _ library.js : https://github.com/emscripten-core/emscripten/blob/main/src/library.js
847
- .. _test_jslib : https://github.com/emscripten-core/emscripten/blob/1.29.12/tests /test_core.py#L5043
844
+ .. _ core JS library : https://github.com/emscripten-core/emscripten/blob/main/src/lib/
845
+ .. _test_jslib : https://github.com/emscripten-core/emscripten/blob/4.0.9/test /test_core.py#L6261
848
846
.. _tools/system_libs.py : https://github.com/emscripten-core/emscripten/blob/main/tools/system_libs.py
849
847
.. _library_\* .js : https://github.com/emscripten-core/emscripten/tree/main/src
850
848
.. _test_add_function in test/test_core.py : https://github.com/emscripten-core/emscripten/blob/1.29.12/tests/test_core.py#L6237
0 commit comments