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'
port = 7000
s = TCPSocket.open(hostname, port)
print "Which port @ loclhost?"
port = gets
print "What to echo? "
q = gets
s.print(q.chop)
s = TCPSocket.open(hostname, port.chop)
s.print("{\"request\": \"define\"}")
while true
line = s.gets # Read lines from the socket

View file

@ -72,8 +72,10 @@ handle_cast(stop, State) ->
{stop, normal, 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,
gen_tcp:send(Socket, io_lib:fwrite("~p~n", [Parsed])),
{noreply, State#state{request_count = RequestCount + 1}};
handle_info(timeout, #state{lsock = LSock} = State) ->
@ -90,8 +92,10 @@ code_change(_OldVsn, State, _Extra) ->
%% Internal functions
%%-----------------------------------------------------
do_JSCall(Socket, Data) ->
io:format("Data: ~p", [Data]),
Port = js_runner:boot(),
Ret = js_runner:executeJS(Port, Data),
do_JSDefine(Socket, Data) ->
JSVM = js_runner:boot(),
Ret = js_runner:define(JSVM, Data),
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).
-export([executeJS/2, boot/0]).
-export([define/2,call/3, boot/0]).
boot() ->
erlang_js:start(),
{ok, Port} = js_driver:new(),
Port.
executeJS(Port, Data) ->
ok = js:define(Port, <<"function helloworld(name){return 'Hello, ' + name}">>),
js:call(Port, <<"helloworld">>, [list_to_binary(Data)]).
define(Port, Data) ->
ok = js:define(Port, 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
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).'