Skip to content

Commit c858815

Browse files
committed
Update / clarify docs for JS library usage
See #24276
1 parent 26b4bce commit c858815

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

site/source/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.rst

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -362,20 +362,18 @@ Implement a C API in JavaScript
362362
It is possible to implement a C API in JavaScript! This is the approach
363363
used in many of Emscripten's libraries, like SDL1 and OpenGL.
364364

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.
379377

380378
As a simple example, consider the case where you have some C code like this:
381379

@@ -843,8 +841,8 @@ on Emscripten. If you would like to port existing Node-API addon to WebAssembly
843841
or compile the same binding code to both Node.js native addon and WebAssembly,
844842
you can give it a try. See `Emnapi documentation`_ for more details.
845843

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/bbf1caa6e24f64fca9eb6a13a9e02d3f42123e77/test/test_core.py#L6261
848846
.. _tools/system_libs.py: https://github.com/emscripten-core/emscripten/blob/main/tools/system_libs.py
849847
.. _library_\*.js: https://github.com/emscripten-core/emscripten/tree/main/src
850848
.. _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

Comments
 (0)