From 6ebf2545d63d99d7595c482ef3949719843873d5 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 19 Jan 2020 11:49:49 +0100 Subject: [PATCH] web: get_value function --- hyperweb.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hyperweb.cpp b/hyperweb.cpp index d8b5c4e3..b393b2b1 100644 --- a/hyperweb.cpp +++ b/hyperweb.cpp @@ -51,12 +51,29 @@ namespace hr { void loadCompressedChar(int &otwidth, int &otheight, int *tpix); const char *wheresounds; + + std::string get_value(std::string name); } #include "hyper.cpp" namespace hr { +string get_value(string name) { + char *str = (char*)EM_ASM_INT({ + var name = UTF8ToString($0, $1); + var value = document.getElementById(name).value; + var lengthBytes = lengthBytesUTF8(value)+1; + var stringOnWasmHeap = _malloc(lengthBytes); + stringToUTF8(value, stringOnWasmHeap, lengthBytes); + return stringOnWasmHeap; + }, name.c_str(), int(name.size()) + ); + string res = str; + free(str); + return res; + } + // -- demo -- #if CAP_URL