You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is very similar to the code in #37, except that the server now uses a further module, provided by the file interaction.pl with the following content:
:- module(interaction, [main/0]).
main :-
format("hello!", []).
The intention here is that format/2in the submodule should also be rewritten (or reinterpreted) by pengines_io, so that I get decorated output from the submodule without having to change the submodule's code.
As a test case, I use demo.html:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Demo</title>
<script src="js/pengines.js"></script>
</head>
<body style="padding-left: 5%; padding-right: 5%">
<br><br>
<script>
var p = new Pengine({
oncreate: function () { p.ask('main'); },
onoutput: function () { console.log(this.data); },
application: "myapp",
server: "pengine",
});
</script>
</body>
</html>
Please start the server with:
$ swipl server.pl --port=5055 --interactive
and then visit http://localhost:5055/demo.html.
Judging from the JavaScript console, main/0 is not affected by the pengines_io declarations in server.pl.
Is this the intended behaviour? If so, could you please explain how I can obtain decorated output in the submodule too? Thank you!
The text was updated successfully, but these errors were encountered:
Just a quick reply now. The pengines_io rebinds write/1, etc. to make nice Prolog terms. It does so by redefining these terms. There is not much choice: once you have a stream that contains a mixture of text and terms it gets hard. That is why it doesn't work for subodules. In addition the library rebinds the standard I/O streams to cacture output and forwards it to the client. That provides raw <pre> output from modules that try to write.
This whole stuff is primarily there to make SWISH work. You best look at the swish source to see how it is deployed.
Let
server.pl
consist of the following code:This is very similar to the code in #37, except that the server now uses a further module, provided by the file
interaction.pl
with the following content:The intention here is that
format/2
in the submodule should also be rewritten (or reinterpreted) bypengines_io
, so that I get decorated output from the submodule without having to change the submodule's code.As a test case, I use
demo.html
:Please start the server with:
and then visit
http://localhost:5055/demo.html
.Judging from the JavaScript console,
main/0
is not affected by thepengines_io
declarations inserver.pl
.Is this the intended behaviour? If so, could you please explain how I can obtain decorated output in the submodule too? Thank you!
The text was updated successfully, but these errors were encountered: