Closed triska closed 6 years ago
Let server.pl consist of the following code:
server.pl
:- module(server, []). :- use_module(library(pengines)). :- use_module(library(http/thread_httpd)). :- use_module(library(http/http_dispatch)). :- use_module(library(http/http_server_files)). :- use_module(library(http/http_files)). :- use_module(library(http/http_unix_daemon)). :- pengine_application(myapp). :- use_module(myapp:library(pengines_io)). pengines:prepare_module(Module, myapp, _Options) :- pengines_io:pengine_bind_io_to_html(Module). myapp:pred :- format("pred\n", []). :- http_handler(/, http_reply_from_files(., []), [prefix]).
Let demo.html consist of:
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('pred'); }, onoutput: function () { console.log(this.data); }, application: "myapp", server: "pengine", }); </script> </body> </html>
Start the server with:
$ swipl server.pl --port=5055 --interactive
and direct your browser to http://localhost:5055/demo.html.
http://localhost:5055/demo.html
If everything works, you see in the JavaScript console:
<pre class="console"> pred </pre>
This means that pengines_io has done its job, because the output is decorated.
pengines_io
In contrast, if we change the definition of myapp:pred/0 to:
myapp:pred/0
myapp:pred :- format("pred\n", []), flush_output.
Then we get:
No permission to call sandboxed `flush_output' Reachable from: '93592351277906267204527080385574986579':pred
From the source of pengines_io, it seems that support for flush_output is intended. However, it seems as if it does not work.
flush_output
In the meanwhile this was emulated, but not properly declared. Fixed. Submodules may do output in recent versions as the current output stream is redefined.
Let
server.pl
consist of the following code:Let
demo.html
consist of:Start the server with:
and direct your browser to
http://localhost:5055/demo.html
.If everything works, you see in the JavaScript console:
This means that
pengines_io
has done its job, because the output is decorated.In contrast, if we change the definition of
myapp:pred/0
to:Then we get:
From the source of
pengines_io
, it seems that support forflush_output
is intended. However, it seems as if it does not work.