summaryrefslogtreecommitdiff
path: root/web/static
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-04-27 05:07:10 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-04-27 05:13:33 -0700
commit04592cc177289cfbc4f596f3f51da83d33688227 (patch)
treedf044b2ce4b9f7bed68c18dc1500da29e202fd60 /web/static
parent91975ac3a86e3644503e263d53c1ea870816354a (diff)
downloaddartboat-04592cc177289cfbc4f596f3f51da83d33688227.tar.gz
dartboat-04592cc177289cfbc4f596f3f51da83d33688227.tar.xz
web: let's use our new function
Diffstat (limited to 'web/static')
-rw-r--r--web/static/dartboat.js26
1 files changed, 11 insertions, 15 deletions
diff --git a/web/static/dartboat.js b/web/static/dartboat.js
index e43488b..4c2be26 100644
--- a/web/static/dartboat.js
+++ b/web/static/dartboat.js
@@ -19,12 +19,15 @@ function scheduleCCall(f, ms, ...args) {
setTimeout(() => Module[`_${func}`](...args), ms);
}
-function promptGet() {
- let tc = document.getElementById('prompt-input').textContent;
- let len = lengthBytesUTF8(tc) + 1;
- let str = _malloc(len);
- stringToUTF8(tc, str, len);
- return str;
+function toCString(str) { // caller must free
+ const len = lengthBytesUTF8(str) + 1;
+ const cstr = _malloc(len);
+ stringToUTF8(str, cstr, len);
+ return cstr;
+}
+
+function promptGet() { // caller must free
+ return toCString(document.getElementById('prompt-input').textContent);
}
function setPromptActive() {
@@ -47,16 +50,9 @@ function promptMsgR(p) {
document.getElementById('prompt-msg-r').textContent = UTF8ToString(p);
}
-function stringToCString(str) { // caller must free
- const len = lengthBytesUTF8(str) + 1;
- const cstr = _malloc(len);
- stringToUTF8(str, cstr, len);
- return cstr;
-}
-
function promptHandle(command, data) {
- const str_c = stringToCString(command);
- const str_d = data && stringToCString(data);
+ const str_c = toCString(command);
+ const str_d = data && toCString(data);
_prompt_handle(str_c, str_d);
_free(str_c);