-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: new javascript wrapper for tests
- Loading branch information
Showing
4 changed files
with
79 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const fs = require('fs') | ||
const util = require('util') | ||
|
||
const C = require(process.argv[2])() // 1st arg is path to WASM zenroom.js | ||
|
||
|
||
const zencodeExec = function(script, conf = null, keys = null, data = null) { | ||
C.then(function(Module){ | ||
Module.exec_ok = () => 0 | ||
Module.exec_error = () => 0 | ||
Module.print = text => console.log(text) | ||
Module.printErr = text => console.error(text) | ||
Module.ccall( | ||
'zencode_exec', | ||
'number', | ||
['string', 'string', 'string', 'string', 'number'], | ||
[script, conf, keys, data] | ||
) | ||
}) | ||
} | ||
const zencode = function(script_file, conf_string=null, keys_file=null, data_file=null) { | ||
const enc = { encoding: 'utf8' } | ||
const script = fs.readFileSync(script_file, enc) | ||
const conf = conf_string | ||
const keys = (keys_file) ? fs.readFileSync(keys_file, enc) : null | ||
const data = (data_file) ? fs.readFileSync(data_file, enc) : null | ||
return zencodeExec(script, conf, keys, data) | ||
} | ||
|
||
// console.log("[JS] zenroom %s %s %s %s", | ||
// process.argv[3], // script file | ||
// process.argv[4], // conf string | ||
// process.argv[5], // keys file | ||
// process.argv[6], // data file | ||
// ) | ||
|
||
// console.time(process.argv[3]) | ||
zencode(process.argv[3],process.argv[4],process.argv[5],process.argv[6]) | ||
// console.timeEnd(process.argv[3]) | ||
// console.log("@", "=".repeat(40), "@\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
# template: %PATH% has to be subsituted with absolute path | ||
# this is processed by check-js to create a zenroom wrapper | ||
|
||
conf=${conf:-"logfmt=text,debug=0"} | ||
|
||
while getopts "zc:k:a:" arg; do | ||
case $arg in | ||
z) ;; # autodetected from script name | ||
k) keys="${OPTARG}" ;; | ||
a) data="${OPTARG}" ;; | ||
c) conf="${OPTARG},logfmt=text,debug=0" ;; | ||
esac | ||
done | ||
shift $((OPTIND-1)) | ||
|
||
if [[ $1 == *.lua ]]; then | ||
node =ROOT=/test/zenroom_exec.js \ | ||
=ROOT=/bindings/javascript/dist/main/zenroom.js $1 $conf $keys $data | ||
elif [[ $1 == *.zen ]]; then | ||
node =ROOT=/test/zencode_exec.js \ | ||
=ROOT=/bindings/javascript/dist/main/zenroom.js $1 $conf $keys $data | ||
else | ||
echo "Unsupported script: $1" | ||
fi |