Skip to content

Commit

Permalink
rework sigsg
Browse files Browse the repository at this point in the history
  • Loading branch information
esromneb committed Sep 27, 2020
1 parent 70d6463 commit 351f988
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
20 changes: 12 additions & 8 deletions lib/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() => {
Expand All @@ -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 {
Expand All @@ -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) => {

Expand Down
30 changes: 23 additions & 7 deletions wasm_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 351f988

Please sign in to comment.