Reverted to erlang_js
This commit is contained in:
parent
4965013fc9
commit
dcab797d0f
4 changed files with 21 additions and 14 deletions
|
@ -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
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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
2
start
|
@ -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).'
|
||||||
|
|
Reference in a new issue