1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-06-23 13:43:19 +00:00

web: get_value function

This commit is contained in:
Zeno Rogue 2020-01-19 11:49:49 +01:00
parent 4b7739e80d
commit 6ebf2545d6

View File

@ -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