summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pd_client.pl24
1 files changed, 24 insertions, 0 deletions
diff --git a/pd_client.pl b/pd_client.pl
new file mode 100644
index 0000000..e0a83f3
--- /dev/null
+++ b/pd_client.pl
@@ -0,0 +1,24 @@
+start(Module):-start(Module, localhost).
+start(Module, Host):-start(Module, Host, 8068).
+
+start(Module, Host, Port):-
+ socket('AF_INET', Socket),
+ hostname_address(Host, HostAddress),
+ socket_connect(Socket, 'AF_INET'(HostAddress, Port),
+ StreamIn, StreamOut),
+ launch(Module, StreamIn, StreamOut),
+ socket_close(Socket).
+
+launch(Module, StreamIn, StreamOut) :-
+ atom_concat('rules/', Module, Path), consult(Path),
+ do([], StreamIn, StreamOut, Module, [], []).
+
+do(e, _, _, _, _) :- !.
+do(Choice, StreamIn, StreamOut, Module, ModuleState, Hist) :-
+ call(Module, Hist, ModuleDecision, ModuleState, NewModuleState),
+ write(StreamOut, ModuleDecision), flush_output(StreamOut),
+ loop(StreamIn, StreamOut, Module, NewModuleState, [Choice|Hist]).
+
+loop(StreamIn, StreamOut, Module, ModuleState, Hist) :-
+ read_atom(StreamIn, Choice), write(Choice),
+ do(Choice, StreamIn, StreamOut, Module, ModuleState, Hist).