hermann on Fri, 24 May 2024 22:37:42 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Making use of "GP in your browser" questions


On 2024-05-24 13:48, hermann@stamm-wilbrandt.de wrote:


Questions:
1) is there some doc on how to correctly make use of

function myevalm(s) { return
Module.ccall("gp_embedded","string",["string"],[s]); }

in browser JavaScript?

Bill pointed me to a wrong file location in directory structure.
This works:

hermann@j4105:~$ tree gp
gp
├── PARI_GP Development Headquarters_files
│   ├── gp-sta.js
│   ├── gp-sta.wasm
│   ├── Logo_PARI-GP_Couleurs_L150px.png
│   └── pari.css
└── PARI_GP Development Headquarters.html

1 directory, 5 files
hermann@j4105:~$

2) Is it OK to use

https://pari.math.u-bordeaux.fr/gpwasm/gp-sta.wasm

in own webpages for using myevalm() ?

I did simplify the webpage further and further until I reached only 24 lines.
Then I realized that I run into CORS issues.
So I did need to copy gp-sta.js and gp-sta.wasm from
https://pari.math.u-bordeaux.fr/gpjswasm/
and store them locally to minimal.html:

$ ssh web23.web138@stamm-wilbrandt.de ls -l httpdocs/gp
web23.web138@stamm-wilbrandt.de's password:
total 13828
-rw-r--r-- 1 web23.web138 psacln   105545 24. Mai 22:07 gp-sta.js
-rw-r--r-- 1 web23.web138 psacln 14047724 24. Mai 22:07 gp-sta.wasm
-rw-r--r-- 1 web23.web138 psacln     1127 24. Mai 22:17 minimal.html
$

That really works, you can try:

https://stamm-wilbrandt.de/gp/minimal.html

??primes results in

Help: https://pari.math.u-bordeaux.fr/dochtml/help-stable/primes.

?primes gives help in browser console:

primes(n): returns the vector of the first n primes (integer), or the primes in gp-sta.js:1:15229
interval n = [a,b].    gp-sta.js:1:15229
<empty string>    gp-sta.js:1:15229

Input [p|p<-primes([2,100]),p%4==1] and then pressing "eval" button results in:

%4 = [5, 13, 17, 29, 37, 41, 53, 61, 73, 89, 97]


The big question is, whether I am allowed to store gp-sta.js and gp-sta.wasm on my website?


The more important question is whether JSCAD (JavaScript) script allows to fetch

https://pari.math.u-bordeaux.fr/gpjswasm/gp-sta.js

by injecting appropriate CORS headers, and thus not requiring that file to be stored on https://jscad.app


Regards,

Hermann.


P.S:
Just because minimal.html is so small ...

<pre id="output"></pre>
<textarea id="code input"></textarea>
<button type="button" id="loading" onclick="eval()">eval</button>
<script type="text/javascript">
  var input = document.getElementById("code input");
  var output = document.getElementById("output");
  var but = document.getElementById("loading");
  but.setAttribute("disabled",true);
  var initonce = false;
  function mystart() { myinit(); initonce = true;
                       but.removeAttribute("disabled"); }
  var Module = { noInitialRun: true, onRuntimeInitialized: mystart };
  function myinit() { Module.ccall("gp_embedded_init",null,["number",
                                   "number"],[4000000,1000000000]); }
  function myevalm(s) { return Module.ccall("gp_embedded",
                                            "string",["string"],[s]); }
  function evalgp(x) {
    var s = myevalm(x);
    if (s == "retry.") { setTimeout(function (){ evalgp(x); }, 500); }
    else               { output.innerHTML = s; }
  }
  function eval() { if (initonce) { evalgp(input.value) } }
</script>
<script async="" type="text/javascript" src="gp-sta.js"></script>