From 351f988fb7e009adb2730aa216437303ac3fec6f Mon Sep 17 00:00:00 2001 From: Ben Date: Sun, 27 Sep 2020 02:15:35 -0700 Subject: [PATCH] rework sigsg --- lib/wrapper.js | 20 ++++++++++++-------- wasm_main.cpp | 30 +++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/lib/wrapper.js b/lib/wrapper.js index 1318bf1..0c55cb9 100644 --- a/lib/wrapper.js +++ b/lib/wrapper.js @@ -19,7 +19,7 @@ module.exports = () => { const bindCWrap = () => { const w = wasm.cwrap; - c.execute = w('execute', 'void', ['number', 'number', 'number', 'number']); + c.execute = w('execute', 'void', ['number', 'number', 'number', 'number', 'number', 'string']); }; const start = async() => { @@ -40,20 +40,24 @@ module.exports = () => { } let boundSet; + let boundGet; // wasm.addFunction can't be called until after // start finishes bindCallback = () => { - boundSet = wasm.addFunction(function(name, len, value) { + boundSet = wasm.addFunction(function(name, len, value) { + let prop = getString(name, len); - let prop = getString(name, len); + console.log(`setting ${prop} to ${value}`); - console.log(`setting ${prop} to ${value}`); + // viii means returns void, accepts int int int + }, 'viii'); - - // vsi means returns void accepts a string and int - }, 'viii'); + boundGet = wasm.addFunction(function(name, len) { + let prop = getString(name, len); + return 42; + }, 'iii'); }; return { @@ -63,7 +67,7 @@ module.exports = () => { console.log(wasm); }, execute: () => { - c.execute(0,0,boundSet,0); + c.execute(0,0,0,boundSet,boundGet,"hi"); }, onB: (time, cmd) => { diff --git a/wasm_main.cpp b/wasm_main.cpp index c68b475..5b46863 100644 --- a/wasm_main.cpp +++ b/wasm_main.cpp @@ -34,34 +34,50 @@ typedef void externalJsMethodOne(const int sz); typedef void externalJsMethodTwo(const char*, const uint64_t time, const uint8_t command, const int dnc0, const int dnc1); -typedef int externalJsGetProperty(const char* name); +typedef int externalJsGetProperty(const char* name, const size_t len); typedef void externalJsSetProperty(const char* name, const size_t len, const int value); /// function pointer for c->js static externalJsMethodOne* externalOne = 0; static externalJsMethodTwo* externalTwo = 0; -static externalJsSetProperty* set_property = 0; -static externalJsGetProperty* get_property = 0; +static externalJsSetProperty* bound_set_property = 0; +static externalJsGetProperty* bound_get_property = 0; + +static void set_property(const char* name, const int value) { + bound_set_property(name, strlen(name), value); +} + +static int get_property(const char* name) { + return bound_get_property(name, strlen(name)); +} extern "C" { void execute( + const int context, externalJsMethodOne* f1, externalJsMethodTwo* f2, externalJsSetProperty* sfn, - externalJsGetProperty* gfn + externalJsGetProperty* gfn, + char* chunk ) { // cout << "execute got " << p << "\n"; - cout << "execute " << (int)sfn << "\n"; - set_property = sfn; + cout << "execute " << (int)sfn << " and got " << chunk << "\n"; + bound_set_property = sfn; + bound_get_property = gfn; - set_property("foo", strlen("foo"), 4); + int got = get_property("bar"); + + cout << "got " << got << " for bar\n"; + + + } } // extern C \ No newline at end of file