Skip to content

Commit

Permalink
adds documentation for create_imports/1
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdovzhanyn committed Jan 24, 2019
1 parent 43739f8 commit 57b4e74
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/execution/host_function.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,32 @@ defmodule WaspVM.HostFunction do
end
end

@doc """
Pass in an Elixir module or list of Elixir modules that implement `defhost`
calls to generate imports for WebAssembly to be passed in when loading a
WebAssembly module into the VM
## Usage
When using a single module to define imports:
WaspVM.HostFunction.create_imports(Module1)
Functions will be accessible in the WebAssembly module as:
(import "Module1" "function_name")
When using multiple modules to define imports:
WaspVM.HostFunction.create_imports([Module1, Module2, Module3])
Functions will be accessible in the WebAssembly module as:
(import "Module1" "function_name")
(import "Module2" "function_name")
(import "Module3" "function_name")
"""
@spec create_imports(list | atom) :: map
def create_imports(modules) when is_list(modules) do
Enum.reduce(modules, %{}, fn mod, acc ->
"Elixir." <> mod_string = to_string(mod)
Expand Down

0 comments on commit 57b4e74

Please sign in to comment.