Reverted to erlang_js

This commit is contained in:
Jonatan Pålsson 2011-01-30 14:14:33 +01:00
parent 4965013fc9
commit dcab797d0f
4 changed files with 21 additions and 14 deletions

View file

@ -5,11 +5,12 @@ require 'socket' # Sockets are in standard library
hostname = 'localhost' hostname = 'localhost'
port = 7000 port = 7000
s = TCPSocket.open(hostname, port) print "Which port @ loclhost?"
port = gets
print "What to echo? " s = TCPSocket.open(hostname, port.chop)
q = gets
s.print(q.chop) s.print("{\"request\": \"define\"}")
while true while true
line = s.gets # Read lines from the socket line = s.gets # Read lines from the socket

View file

@ -72,8 +72,10 @@ handle_cast(stop, State) ->
{stop, normal, State}. {stop, normal, State}.
handle_info({tcp, Socket, RawData}, State) -> handle_info({tcp, Socket, RawData}, State) ->
do_JSCall(Socket, RawData), %do_JSCall(Socket, RawData),
Parsed = ggs_protocol:parse(RawData),
RequestCount = State#state.request_count, RequestCount = State#state.request_count,
gen_tcp:send(Socket, io_lib:fwrite("~p~n", [Parsed])),
{noreply, State#state{request_count = RequestCount + 1}}; {noreply, State#state{request_count = RequestCount + 1}};
handle_info(timeout, #state{lsock = LSock} = State) -> handle_info(timeout, #state{lsock = LSock} = State) ->
@ -90,8 +92,10 @@ code_change(_OldVsn, State, _Extra) ->
%% Internal functions %% Internal functions
%%----------------------------------------------------- %%-----------------------------------------------------
do_JSCall(Socket, Data) -> do_JSDefine(Socket, Data) ->
io:format("Data: ~p", [Data]), JSVM = js_runner:boot(),
Port = js_runner:boot(), Ret = js_runner:define(JSVM, Data),
Ret = js_runner:executeJS(Port, Data),
gen_tcp:send(Socket, io_lib:fwrite("~p~n", [Ret])). gen_tcp:send(Socket, io_lib:fwrite("~p~n", [Ret])).
do_JSCall(Socket, Function, Parameters) ->
ok.

View file

@ -1,11 +1,13 @@
-module(js_runner). -module(js_runner).
-export([executeJS/2, boot/0]). -export([define/2,call/3, boot/0]).
boot() -> boot() ->
erlang_js:start(), erlang_js:start(),
{ok, Port} = js_driver:new(), {ok, Port} = js_driver:new(),
Port. Port.
executeJS(Port, Data) -> define(Port, Data) ->
ok = js:define(Port, <<"function helloworld(name){return 'Hello, ' + name}">>), ok = js:define(Port, list_to_binary(Data)).
js:call(Port, <<"helloworld">>, [list_to_binary(Data)]).
call(Port, Func, Params) ->
js:call(Port, list_to_binary(Func), [Params]).

2
start
View file

@ -1,3 +1,3 @@
#!/usr/bin/env bash #!/usr/bin/env bash
erl -pa erlv8/ebin -pa ebin -pa src erl -boot start_sasl -pa erlang_js/ebin/ -pa erlv8/ebin -pa ebin -pa src -eval 'ggs_server:start_link(9000).'