diff options
Diffstat (limited to 'web')
-rw-r--r-- | web/static/dartboat.js | 26 |
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); |