From one port process to many.
This commit is contained in:
parent
8c1fe0b4fd
commit
e945bb0d31
2 changed files with 37 additions and 25 deletions
|
@ -1,14 +1,12 @@
|
|||
-module(js_runner).
|
||||
-export([boot/0,define/2,call/3]).
|
||||
-export([boot/0]).
|
||||
|
||||
%Mattias
|
||||
boot() ->
|
||||
erlang_js:start(),
|
||||
{ok, Port} = js_driver:new(),
|
||||
PortPid = spawn(fun() ->
|
||||
port_process(Port) end ),
|
||||
register(port_pid, PortPid),
|
||||
Port.
|
||||
PortPid = spawn(fun() -> port_process(Port) end ),
|
||||
PortPid.
|
||||
|
||||
|
||||
port_process(Port) ->
|
||||
|
@ -16,20 +14,20 @@ receive
|
|||
{get_port, From} ->
|
||||
From!{ok,Port},
|
||||
port_process(Port);
|
||||
{define,From, JSVM, Data} ->
|
||||
ok = js:define(JSVM, list_to_binary(Data)),
|
||||
{define, From, Data} ->
|
||||
ok = js:define(From, list_to_binary(Data)),
|
||||
From!{ok},
|
||||
port_process(Port);
|
||||
{call, From, JSVM, Func, Params} ->
|
||||
{ok,Ret} = js:call(JSVM, list_to_binary(Func), Params),
|
||||
{call, From, Func, Params} ->
|
||||
{ok,Ret} = js:call(From, list_to_binary(Func), Params), %Port unsure
|
||||
From!{ok,Ret},
|
||||
port_process(Port)
|
||||
end.
|
||||
|
||||
|
||||
define(Port, Data) ->
|
||||
port_pid!{define,self(),Port,Data}.
|
||||
%These two babies will be ambigiuous
|
||||
%define(Port, Data) ->
|
||||
% port_pid!{define,self(),Port,Data}.
|
||||
|
||||
|
||||
call(Port, Func, Params) ->
|
||||
port_pid!{call, self(), Port, Func, Params}.
|
||||
%call(Port, Func, Params) ->
|
||||
% port_pid!{call, self(), Port, Func, Params}.
|
||||
|
|
Reference in a new issue