mirror of
				https://github.com/zenorogue/hyperrogue.git
				synced 2025-10-31 05:52:59 +00:00 
			
		
		
		
	web: get_value function
This commit is contained in:
		
							
								
								
									
										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 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Zeno Rogue
					Zeno Rogue