Port to process.
This commit is contained in:
parent
3ccef1e711
commit
8c1fe0b4fd
2 changed files with 29 additions and 7 deletions
|
@ -106,13 +106,13 @@ handle_cast({call, Token, Payload}, State) ->
|
||||||
io:format("Got call request: ~p~n", [Payload]),
|
io:format("Got call request: ~p~n", [Payload]),
|
||||||
JSVM = getJSVM(Token, State),
|
JSVM = getJSVM(Token, State),
|
||||||
erlang:display(erlang:port_info(JSVM)),
|
erlang:display(erlang:port_info(JSVM)),
|
||||||
{ok, Ret} = js_runner:call(JSVM, Payload, []),%Payload, []),
|
{ok, Ret} = js_runner:call(JSVM, Payload, []),
|
||||||
send(State#state.lsock, Token, "JS says:", binary_to_list(Ret)),
|
send(State#state.lsock, Token, "JS says:", binary_to_list(Ret)),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
|
|
||||||
% Set the new state to the reference generated, and JSVM associated
|
% Set the new state to the reference generated, and JSVM associated
|
||||||
handle_cast({hello, _, _}, State) ->
|
handle_cast({hello, _, _}, State) ->
|
||||||
JSVM = js_runner:boot(),
|
JSVM = js_runner:boot(),
|
||||||
Client = getRef(),
|
Client = getRef(),
|
||||||
send(State#state.lsock, Client, "This is your refID"),
|
send(State#state.lsock, Client, "This is your refID"),
|
||||||
OldMap = State#state.client_vm_map,
|
OldMap = State#state.client_vm_map,
|
||||||
|
|
|
@ -1,13 +1,35 @@
|
||||||
-module(js_runner).
|
-module(js_runner).
|
||||||
-export([define/2,call/3, boot/0]).
|
-export([boot/0,define/2,call/3]).
|
||||||
|
|
||||||
boot() ->
|
%Mattias
|
||||||
|
boot() ->
|
||||||
erlang_js:start(),
|
erlang_js:start(),
|
||||||
{ok, Port} = js_driver:new(),
|
{ok, Port} = js_driver:new(),
|
||||||
|
PortPid = spawn(fun() ->
|
||||||
|
port_process(Port) end ),
|
||||||
|
register(port_pid, PortPid),
|
||||||
Port.
|
Port.
|
||||||
|
|
||||||
define(Port, Data) ->
|
|
||||||
ok = js:define(Port, list_to_binary(Data)).
|
port_process(Port) ->
|
||||||
|
receive
|
||||||
|
{get_port, From} ->
|
||||||
|
From!{ok,Port},
|
||||||
|
port_process(Port);
|
||||||
|
{define,From, JSVM, Data} ->
|
||||||
|
ok = js:define(JSVM, list_to_binary(Data)),
|
||||||
|
From!{ok},
|
||||||
|
port_process(Port);
|
||||||
|
{call, From, JSVM, Func, Params} ->
|
||||||
|
{ok,Ret} = js:call(JSVM, list_to_binary(Func), Params),
|
||||||
|
From!{ok,Ret},
|
||||||
|
port_process(Port)
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
define(Port, Data) ->
|
||||||
|
port_pid!{define,self(),Port,Data}.
|
||||||
|
|
||||||
|
|
||||||
call(Port, Func, Params) ->
|
call(Port, Func, Params) ->
|
||||||
js:call(Port, list_to_binary(Func), Params).
|
port_pid!{call, self(), Port, Func, Params}.
|
||||||
|
|
Reference in a new issue