Skip to content

Commit 9adeb3b

Browse files
committed
Rename foreign to defexternal
1 parent 508b922 commit 9adeb3b

File tree

5 files changed

+17
-21
lines changed

5 files changed

+17
-21
lines changed

JavascriptInterop.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ Here is an example of a foreign module for a JSON module
2525
defmodule MyApp.JSON do
2626
use ElixirScript.FFI
2727

28-
foreign stringify(map)
29-
foreign parse(string)
28+
defexternal stringify(map)
29+
defexternal parse(string)
3030
end
3131
```
3232

33-
Foreign modules map to JavaScript files that export functions defined with the `foreign` macro.
33+
Foreign modules map to JavaScript files that export functions defined with the `defexternal` macro.
3434
ElixirScript expects JavaScript modules to be in the `priv/elixir_script` directory.
3535
These modules are copied to the output directory upon compilation.
3636

lib/elixir_script/compiler.ex

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@ defmodule ElixirScript.Compiler do
1616

1717
entry_modules = List.wrap(entry_modules)
1818

19-
IO.puts "Finding used modules"
2019
ElixirScript.FindUsedModules.execute(entry_modules, pid)
2120

22-
IO.puts "Finding used functions"
2321
ElixirScript.FindUsedFunctions.execute(entry_modules, pid)
2422

25-
IO.puts "Compiling"
2623
modules = ElixirScript.State.list_modules(pid)
2724
ElixirScript.Translate.execute(modules, pid)
2825

29-
IO.puts "Building Output"
3026
modules = ElixirScript.State.list_modules(pid)
3127
result = ElixirScript.Output.execute(modules, pid)
3228

@@ -56,4 +52,4 @@ defmodule ElixirScript.Compiler do
5652
defp get_module_formatter(_) do
5753
ElixirScript.ModuleSystems.ES
5854
end
59-
end
55+
end

lib/elixir_script/ffi.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ defmodule ElixirScript.FFI do
33
The foreign function interface for interacting with JavaScript
44
55
To define a foreign module, make a new module and add `use ElixirScript.FFI`. to it
6-
To define foreign functions, use the `foreign` macro.
6+
To define external functions, use the `defexternal` macro.
77
88
Here is an example of a foreign module for a JSON module
99
1010
```elixir
1111
defmodule MyApp.JSON do
1212
use ElixirScript.FFI
1313
14-
foreign stringify(map)
15-
foreign parse(string)
14+
defexternal stringify(map)
15+
defexternal parse(string)
1616
end
1717
```
1818
19-
Foreign modules map to JavaScript files that export functions defined with the `foreign` macro.
19+
Foreign modules map to JavaScript files that export functions defined with the `defexternal` macro.
2020
ElixirScript expects JavaScript modules to be in the `priv/elixir_script` directory.
2121
These modules are copied to the output directory upon compilation.
2222
@@ -46,13 +46,13 @@ defmodule ElixirScript.FFI do
4646
@doc """
4747
Defines a JavaScript function to be called from Elixir modules
4848
49-
To define a foreign function, pass the name and arguments to `foreign`
49+
To define an external function, pass the name and arguments to `defexternal`
5050
5151
```elixir
52-
foreign my_js_function(arg1, arg2, arg3)
52+
defexternal my_js_function(arg1, arg2, arg3)
5353
```
5454
"""
55-
defmacro foreign({name, _, args}) do
55+
defmacro defexternal({name, _, args}) do
5656
args = Enum.map(args, fn
5757
{:\\, meta0, [{name, meta, atom}, value]}->
5858
name = String.to_atom("_" <> Atom.to_string(name))

lib/elixir_script/lib/store.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ defmodule ElixirScript.Core.Store do
22
@moduledoc false
33
use ElixirScript.FFI, global: true
44

5-
foreign create(value, name \\ nil)
5+
defexternal create(value, name \\ nil)
66

7-
foreign update(key, value)
7+
defexternal update(key, value)
88

9-
foreign read(key)
9+
defexternal read(key)
1010

11-
foreign remove(key)
11+
defexternal remove(key)
1212
end

test/ffi_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule ElixirScript.FFI.Test do
44
defmodule MyTestModule do
55
use ElixirScript.FFI
66

7-
foreign my_test_function(arg1, arg2)
7+
defexternal my_test_function(arg1, arg2)
88
end
99

1010
test "FFI module has __foreign_info__ attribute" do
@@ -14,4 +14,4 @@ defmodule ElixirScript.FFI.Test do
1414
test "FFI module makes foreign function" do
1515
assert Keyword.has_key?(MyTestModule.__info__(:functions), :my_test_function)
1616
end
17-
end
17+
end

0 commit comments

Comments
 (0)