This repository has been archived on 2025-08-18. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
GGS/src/js_runner.erl
2011-02-14 15:09:01 +01:00

33 lines
782 B
Erlang

-module(js_runner).
-export([boot/0]).
%Mattias
boot() ->
erlang_js:start(),
{ok, Port} = js_driver:new(),
PortPid = spawn(fun() -> port_process(Port) end ),
PortPid.
port_process(Port) ->
receive
{get_port, From} ->
From!{ok,Port},
port_process(Port);
{define, From, Data} ->
ok = js:define(From, list_to_binary(Data)),
From!{ok},
port_process(Port);
{call, From, Func, Params} ->
{ok,Ret} = js:call(From, list_to_binary(Func), Params), %Port unsure
From!{ok,Ret},
port_process(Port)
end.
%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}.