Merge branch 'master' of https://github.com/jonte/GGS into jonte-master
This commit is contained in:
commit
34b4c1d072
13 changed files with 15541 additions and 15 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +1,6 @@
|
|||
[submodule "erlang_js"]
|
||||
path = erlang_js
|
||||
url = https://github.com/basho/erlang_js.git
|
||||
[submodule "erlv8"]
|
||||
path = erlv8
|
||||
url = https://github.com/beamjs/erlv8.git
|
||||
|
|
8
build_test
Executable file
8
build_test
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
./build
|
||||
|
||||
for i in `find tests -name "*.erl"`
|
||||
do
|
||||
erlc -o ebin_test $i
|
||||
done
|
|
@ -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(" __boot")
|
||||
|
||||
while true
|
||||
line = s.gets # Read lines from the socket
|
||||
|
|
15446
erl_crash.dump
Normal file
15446
erl_crash.dump
Normal file
File diff suppressed because one or more lines are too long
1
erlv8
Submodule
1
erlv8
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 688e5036864eed01f7aefb6ee8b3a4c22961012f
|
26
src/ggs_protocol.erl
Normal file
26
src/ggs_protocol.erl
Normal file
|
@ -0,0 +1,26 @@
|
|||
%% This is a parser for JSON implemented using mochijson2
|
||||
%% Don't feed it anything other than valid JSON.
|
||||
|
||||
-module(ggs_protocol).
|
||||
-export([parse/1]).
|
||||
|
||||
parse(Data) ->
|
||||
Message = string:tokens(Data, " "),
|
||||
case Message of
|
||||
[RefID, "__error", Message ] ->
|
||||
{ok, you_said_error};
|
||||
[_, "__boot" ] ->
|
||||
{ok, you_said_boot};
|
||||
[RefID, "__stop"] ->
|
||||
{ok, you_said_stop};
|
||||
[RefID, "__start"] ->
|
||||
{ok, you_said_start};
|
||||
[_, "__hello" , _ ] ->
|
||||
{ok, you_said_hello};
|
||||
[RefID, "__define", JavaScript ] ->
|
||||
{ok, you_said_define};
|
||||
[RefID, Command, Parameter ] ->
|
||||
{cmd, Command, Parameter};
|
||||
Other ->
|
||||
{out_of_bounds, Other}
|
||||
end.
|
|
@ -72,8 +72,10 @@ handle_cast(stop, State) ->
|
|||
{stop, normal, State}.
|
||||
|
||||
handle_info({tcp, Socket, RawData}, State) ->
|
||||
do_JSCall(Socket, RawData),
|
||||
do_JSDefine(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,19 @@ 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),
|
||||
gen_tcp:send(Socket, io_lib:fwrite("~p~n", [Ret])).
|
||||
do_JSDefine(Socket, Data) ->
|
||||
JSVM = js_runner:boot(),
|
||||
js_runner:define(JSVM, "function userCommand(cmd, par) {return cmd+' '+ par}"),
|
||||
Parsed = ggs_protocol:parse(Data),
|
||||
case Parsed of
|
||||
{cmd, Command, Parameter} ->
|
||||
Ret = js_runner:call(JSVM, "userCommand",
|
||||
[list_to_binary(Command),
|
||||
list_to_binary(Parameter)]),
|
||||
gen_tcp:send(Socket, io_lib:fwrite("JS says: ~p~n", [Ret]));
|
||||
Other ->
|
||||
ok
|
||||
end.
|
||||
|
||||
do_JSCall(Socket, Function, Parameters) ->
|
||||
ok.
|
||||
|
|
|
@ -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).
|
||||
|
|
14
src/v8test.erl
Normal file
14
src/v8test.erl
Normal file
|
@ -0,0 +1,14 @@
|
|||
-module(v8test).
|
||||
-export([run/0]).
|
||||
-include_lib("erlv8/include/erlv8.hrl").
|
||||
|
||||
run() ->
|
||||
application:start(erlv8),
|
||||
{ok, VM} = erlv8_vm:start(),
|
||||
Global = erlv8_vm:global(VM),
|
||||
Global:set_value("callback", erlv8_object:new([{"exec", fun (#erlv8_fun_invocation{}, []) -> myCallback() end}])),
|
||||
erlv8_vm:run(VM,"callback.exec();").
|
||||
|
||||
myCallback() ->
|
||||
io:format("Hello from myCallback!~n", []),
|
||||
ok.
|
2
start
2
start
|
@ -1,3 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
erl -boot start_sasl -pa ebin -pa erlang_js/ebin/ -pa src -eval 'ggs_server:start_link(7000)'
|
||||
erl -boot start_sasl -pa erlang_js/ebin/ -pa erlv8/ebin -pa ebin -pa src -eval "ggs_server:start_link($1)."
|
||||
|
|
3
start_test
Executable file
3
start_test
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
erl -boot start_sasl -pa ebin_test -pa erlang_js/ebin/ -pa erlv8/ebin -pa ebin -pa src -eval 'ggs_protocol_test:test_parse().'
|
3
start_test_shell
Executable file
3
start_test_shell
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
erl -boot start_sasl -pa ebin_test -pa erlang_js/ebin/ -pa erlv8/ebin -pa ebin -pa src
|
6
tests/ggs_protocol_test.erl
Normal file
6
tests/ggs_protocol_test.erl
Normal file
|
@ -0,0 +1,6 @@
|
|||
-module(ggs_protocol_test).
|
||||
-export([test_parse/0]).
|
||||
|
||||
test_parse() ->
|
||||
Ret = ggs_protocol:parse("<> __define JavaScript"),
|
||||
io:format("~p~n", [Ret]).
|
Reference in a new issue