Now we can run javascript and send back the return values
This commit is contained in:
parent
c88dcf7829
commit
b1a65ef0ac
8 changed files with 10 additions and 3 deletions
BIN
js_runner.beam
Normal file
BIN
js_runner.beam
Normal file
Binary file not shown.
|
@ -1,7 +1,11 @@
|
|||
-module(js_runner).
|
||||
-export([run/0]).
|
||||
-export([executeJS/2, 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">>, [<<"Generic Game Server">>]).
|
||||
js:call(Port, <<"helloworld">>, [Data]).
|
||||
|
|
BIN
js_test.beam
BIN
js_test.beam
Binary file not shown.
BIN
src/.ggs_server.erl.swo
Normal file
BIN
src/.ggs_server.erl.swo
Normal file
Binary file not shown.
BIN
src/ggs_app.beam
Normal file
BIN
src/ggs_app.beam
Normal file
Binary file not shown.
Binary file not shown.
|
@ -75,6 +75,7 @@ handle_info({tcp, Socket, RawData}, State) ->
|
|||
do_JSCall(Socket, RawData),
|
||||
RequestCount = State#state.request_count,
|
||||
{noreply, State#state{request_count = RequestCount + 1}};
|
||||
|
||||
handle_info(timeout, #state{lsock = LSock} = State) ->
|
||||
{ok, _Sock} = gen_tcp:accept(LSock),
|
||||
{noreply, State}.
|
||||
|
@ -90,7 +91,9 @@ code_change(_OldVsn, State, _Extra) ->
|
|||
%%-----------------------------------------------------
|
||||
|
||||
do_JSCall(Socket, Data) ->
|
||||
gen_tcp:send(Socket, io_lib:fwrite("~p~n", ["I got a call from j00!"])).
|
||||
Port = js_runner:boot(),
|
||||
Ret = js_runner:executeJS(Port, Data),
|
||||
gen_tcp:send(Socket, io_lib:fwrite("~p~n", [Ret])).
|
||||
|
||||
args_to_terms(RawArgs) ->
|
||||
{ok, Toks, _Line} = erl_scan:string("[" ++ RawArgs ++ "]. ", 1),
|
||||
|
|
BIN
src/ggs_sup.beam
Normal file
BIN
src/ggs_sup.beam
Normal file
Binary file not shown.
Reference in a new issue