File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed
Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change 11defmodule ElixirScript.FFI do
22 @ moduledoc """
33 The foreign function interface for interoperability with JavaScript.
4+
5+ Define foreign modules with `use ElixirScript.FFI`.
6+ Next to define functions for the foreign module, use the `foreign` macro.
7+
8+ Here is an example of a foreign module for a JSON module
9+
10+ ```elixir
11+ defmodule MyApp.JSON do
12+ use ElixirScript.FFI
13+
14+ foreign stringify(map)
15+ foreign parse(string)
16+ end
17+ ```
18+
19+ Foreign modules must have an equivalent JavaScript module.
20+ ElixirScript expects JavaScript modules to be in the `priv/elixir_script` directory.
21+ These modules will be copied to the output directory upon compilation.
22+
23+ In the example, a JavaScript file must be at `priv/elixir_script/my_app/json.js`.
24+ It looks like this
25+ ```javascript
26+ export default {
27+ stringify: JSON.stringify,
28+ parse: JSON.parse
29+ }
30+ ```
31+
32+ The JavaScript module must export a default object with the foreign functions defined in the Elixir module
433 """
534
635 defmacro __using__ ( opts ) do
Original file line number Diff line number Diff line change 11defmodule Main do
22 def start ( :normal , [ callback ] ) do
33 callback . ( "started" )
4- Agent . start ( fn ( ) -> nil end )
5- Data.JSON . stringify ( % { } )
64 end
75end
You can’t perform that action at this time.
0 commit comments