mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
new files to make EM_JS stuff sharable
This commit is contained in:
parent
007e1e4acb
commit
5abf13c4a2
4 changed files with 68 additions and 37 deletions
|
@ -20,7 +20,7 @@ include ../common/config.mk
|
|||
|
||||
DEBS = cmake
|
||||
|
||||
INPUTS = main.c wasmdict.c wasmutls.c wasmdraw.c wasmutil.c wasmdutil.c ${COMMONSRC}
|
||||
INPUTS = main.c wasmdict.c wasmutls.c wasmdraw.c wasmutil.c wasmdutil.c wasmasm.c ${COMMONSRC}
|
||||
|
||||
DEFINES += -DXWFEATURE_CHAT
|
||||
DEFINES += -DXWFEATURE_BONUSALL
|
||||
|
|
40
xwords4/wasm/wasmasm.c
Normal file
40
xwords4/wasm/wasmasm.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* -*- compile-command: "cd ../wasm && make -j3 MEMDEBUG=TRUE install"; -*- */
|
||||
/*
|
||||
* Copyright 2021 by Eric House (xwords@eehouse.org). All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <emscripten.h>
|
||||
|
||||
#include "wasmasm.h"
|
||||
|
||||
EM_JS(const char*, get_stored_value, (const char* key), {
|
||||
var result = null;
|
||||
var jsKey = UTF8ToString(key);
|
||||
var jsString = localStorage.getItem(jsKey);
|
||||
if ( jsString != null ) {
|
||||
var lengthBytes = lengthBytesUTF8(jsString)+1;
|
||||
result = _malloc(lengthBytes);
|
||||
stringToUTF8(jsString, result, lengthBytes);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
EM_JS(void, set_stored_value, (const char* key, const char* val), {
|
||||
var jsKey = UTF8ToString(key);
|
||||
var jsVal = UTF8ToString(val);
|
||||
var jsString = localStorage.setItem(jsKey, jsVal);
|
||||
});
|
26
xwords4/wasm/wasmasm.h
Normal file
26
xwords4/wasm/wasmasm.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* -*- compile-command: "cd ../wasm && make main.html -j3"; -*- */
|
||||
/*
|
||||
* Copyright 2021 by Eric House (xwords@eehouse.org). All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef _WASMASM_H_
|
||||
#define _WASMASM_H_
|
||||
|
||||
const char* get_stored_value( const char* key );
|
||||
void set_stored_value(const char* key, const char* val);
|
||||
|
||||
#endif
|
|
@ -25,6 +25,7 @@
|
|||
#include "main.h"
|
||||
#include "dbgutil.h"
|
||||
#include "LocalizedStrIncludes.h"
|
||||
#include "wasmasm.h"
|
||||
|
||||
typedef struct _WasmDUtilCtxt {
|
||||
XW_DUtilCtxt super;
|
||||
|
@ -162,42 +163,6 @@ base16Decode( uint8_t* decodeBuf, int len, const char* str )
|
|||
XP_ASSERT( offset == len );
|
||||
}
|
||||
|
||||
/* static void testBase16() */
|
||||
/* { */
|
||||
/* const XP_U8 testBuf[] = {0x03, 0x04, 0x78, 0xF8, 0x99 }; */
|
||||
|
||||
/* XP_UCHAR chars[(VSIZE(testBuf) * 2) + 1]; */
|
||||
/* base16Encode( testBuf, VSIZE(testBuf), chars, sizeof(chars) ); */
|
||||
|
||||
/* int len = XP_STRLEN( chars ); */
|
||||
/* XP_U8 decodeBuf[len / 2]; */
|
||||
/* base16Decode( decodeBuf, VSIZE(decodeBuf), chars ); */
|
||||
|
||||
/* XP_ASSERT( 0 == XP_MEMCMP( testBuf, decodeBuf, VSIZE(testBuf) ) ); */
|
||||
/* } */
|
||||
|
||||
EM_JS(const char*, get_stored_value, (const char* key), {
|
||||
var result = null;
|
||||
var jsKey = UTF8ToString(key);
|
||||
var jsString = localStorage.getItem(jsKey);
|
||||
if ( jsString != null ) {
|
||||
var lengthBytes = lengthBytesUTF8(jsString)+1;
|
||||
var result = _malloc(lengthBytes);
|
||||
stringToUTF8(jsString, result, lengthBytes);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
EM_JS(void, set_stored_value, (const char* key, const char* val), {
|
||||
var jsKey = UTF8ToString(key);
|
||||
var jsVal = UTF8ToString(val);
|
||||
var jsString = localStorage.setItem(jsKey, jsVal);
|
||||
});
|
||||
|
||||
/* EM_JS(void, clear_stored, (), { */
|
||||
/* localStorage.clear(); */
|
||||
/* }); */
|
||||
|
||||
static void
|
||||
wasm_dutil_loadPtr( XW_DUtilCtxt* duc, XWEnv xwe, const XP_UCHAR* key,
|
||||
const XP_UCHAR* keySuffix, void* data, XP_U16* lenp )
|
||||
|
|
Loading…
Add table
Reference in a new issue