mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-09-29 14:30:40 +00:00
web: get_value function
This commit is contained in:
parent
4b7739e80d
commit
6ebf2545d6
17
hyperweb.cpp
17
hyperweb.cpp
@ -51,12 +51,29 @@ namespace hr {
|
|||||||
void loadCompressedChar(int &otwidth, int &otheight, int *tpix);
|
void loadCompressedChar(int &otwidth, int &otheight, int *tpix);
|
||||||
|
|
||||||
const char *wheresounds;
|
const char *wheresounds;
|
||||||
|
|
||||||
|
std::string get_value(std::string name);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "hyper.cpp"
|
#include "hyper.cpp"
|
||||||
|
|
||||||
namespace hr {
|
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 --
|
// -- demo --
|
||||||
|
|
||||||
#if CAP_URL
|
#if CAP_URL
|
||||||
|
Loading…
Reference in New Issue
Block a user