summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-12-28 19:49:36 +1100
committerdaurnimator <quae@daurnimator.com>2017-12-28 20:25:17 +1100
commitab1881cd9f2746ad8e75ba573be34041f95ab5a6 (patch)
treeeeb0e2a676e4fd36615ec6c59a7de4ea1b8b9970 /src
parentab70a8709c6af43311ab716d24f503e3ac2fe37e (diff)
downloadfengari-ab1881cd9f2746ad8e75ba573be34041f95ab5a6.tar.gz
fengari-ab1881cd9f2746ad8e75ba573be34041f95ab5a6.tar.bz2
fengari-ab1881cd9f2746ad8e75ba573be34041f95ab5a6.zip
src/ldblib.js: Use window.prompt to get input in browser
Doesn't work in web workers
Diffstat (limited to 'src')
-rw-r--r--src/ldblib.js22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/ldblib.js b/src/ldblib.js
index a189976..940c525 100644
--- a/src/ldblib.js
+++ b/src/ldblib.js
@@ -395,16 +395,28 @@ const dblib = {
"upvaluejoin": db_upvaluejoin
};
+let getinput;
if (typeof process !== "undefined") { // Only with Node
const readlineSync = require('readline-sync');
readlineSync.setDefaultOptions({
prompt: 'lua_debug> '
});
-
- // TODO: if in browser, use a designated input in the DOM ?
- const db_debug = function(L) {
+ getinput = function() {
+ return readlineSync.prompt();
+ };
+} else if (typeof window !== "undefined") {
+ /* if in browser use window.prompt. Doesn't work from web workers.
+ See https://developer.mozilla.org/en-US/docs/Web/API/Window/prompt
+ */
+ getinput = function() {
+ let input = prompt("lua_debug>", "");
+ return (input !== null) ? input : "";
+ };
+}
+if (getinput) {
+ dblib.debug = function(L) {
for (;;) {
- let input = readlineSync.prompt();
+ let input = getinput();
if (input === "cont")
return 0;
@@ -420,8 +432,6 @@ if (typeof process !== "undefined") { // Only with Node
lua.lua_settop(L, 0); /* remove eventual returns */
}
};
-
- dblib.debug = db_debug;
}
const luaopen_debug = function(L) {