Interface modifications. Methods for vm handling.
This commit is contained in:
parent
05d5b60a9f
commit
1e08fe0015
3 changed files with 42 additions and 62 deletions
28
src/ggs_vm_runner.erl
Normal file
28
src/ggs_vm_runner.erl
Normal file
|
@ -0,0 +1,28 @@
|
|||
-module(ggs_vm_runner).
|
||||
-export([start_link/0, define/2, user_command/4]).
|
||||
|
||||
%Mattias
|
||||
start_link() ->
|
||||
erlang_js:start(),
|
||||
{ok, Port} = js_driver:new(),
|
||||
js:define(Port, <<"function userCommand(user, command, args){}">>),
|
||||
PortPid = spawn_link(fun() -> loop(Port) end ),
|
||||
PortPid.
|
||||
|
||||
|
||||
loop(Port) ->
|
||||
receive
|
||||
{define, SourceCode} ->
|
||||
ok = js:define(Port, list_to_binary(SourceCode)),
|
||||
loop(Port);
|
||||
{user_command, User, Command, Args} ->
|
||||
{ok, Ret} = js:call(Port, <<"userCommand">>, list_to_binary([User,Command,Args])),
|
||||
loop(Port)
|
||||
end.
|
||||
|
||||
|
||||
define(GameVM, SourceCode) ->
|
||||
GameVM ! {define,SourceCode}.
|
||||
|
||||
user_command(GameVM, User, Command, Args) ->
|
||||
GameVM ! {user_command, User, Command, Args}.
|
Reference in a new issue