rework sigsg
This commit is contained in:
parent
70d64632a3
commit
351f988fb7
@ -19,7 +19,7 @@ module.exports = () => {
|
|||||||
|
|
||||||
const bindCWrap = () => {
|
const bindCWrap = () => {
|
||||||
const w = wasm.cwrap;
|
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() => {
|
const start = async() => {
|
||||||
@ -40,20 +40,24 @@ module.exports = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let boundSet;
|
let boundSet;
|
||||||
|
let boundGet;
|
||||||
|
|
||||||
// wasm.addFunction can't be called until after
|
// wasm.addFunction can't be called until after
|
||||||
// start finishes
|
// start finishes
|
||||||
bindCallback = () => {
|
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
|
||||||
// vsi means returns void accepts a string and int
|
|
||||||
}, 'viii');
|
}, 'viii');
|
||||||
|
|
||||||
|
boundGet = wasm.addFunction(function(name, len) {
|
||||||
|
let prop = getString(name, len);
|
||||||
|
return 42;
|
||||||
|
}, 'iii');
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -63,7 +67,7 @@ module.exports = () => {
|
|||||||
console.log(wasm);
|
console.log(wasm);
|
||||||
},
|
},
|
||||||
execute: () => {
|
execute: () => {
|
||||||
c.execute(0,0,boundSet,0);
|
c.execute(0,0,0,boundSet,boundGet,"hi");
|
||||||
},
|
},
|
||||||
onB: (time, cmd) => {
|
onB: (time, cmd) => {
|
||||||
|
|
||||||
|
@ -34,32 +34,48 @@ 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 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);
|
typedef void externalJsSetProperty(const char* name, const size_t len, const int value);
|
||||||
|
|
||||||
|
|
||||||
/// function pointer for c->js
|
/// function pointer for c->js
|
||||||
static externalJsMethodOne* externalOne = 0;
|
static externalJsMethodOne* externalOne = 0;
|
||||||
static externalJsMethodTwo* externalTwo = 0;
|
static externalJsMethodTwo* externalTwo = 0;
|
||||||
static externalJsSetProperty* set_property = 0;
|
static externalJsSetProperty* bound_set_property = 0;
|
||||||
static externalJsGetProperty* get_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" {
|
extern "C" {
|
||||||
|
|
||||||
void execute(
|
void execute(
|
||||||
|
const int context,
|
||||||
externalJsMethodOne* f1,
|
externalJsMethodOne* f1,
|
||||||
externalJsMethodTwo* f2,
|
externalJsMethodTwo* f2,
|
||||||
externalJsSetProperty* sfn,
|
externalJsSetProperty* sfn,
|
||||||
externalJsGetProperty* gfn
|
externalJsGetProperty* gfn,
|
||||||
|
char* chunk
|
||||||
) {
|
) {
|
||||||
|
|
||||||
// cout << "execute got " << p << "\n";
|
// cout << "execute got " << p << "\n";
|
||||||
cout << "execute " << (int)sfn << "\n";
|
cout << "execute " << (int)sfn << " and got " << chunk << "\n";
|
||||||
set_property = sfn;
|
bound_set_property = sfn;
|
||||||
|
bound_get_property = gfn;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int got = get_property("bar");
|
||||||
|
|
||||||
|
cout << "got " << got << " for bar\n";
|
||||||
|
|
||||||
set_property("foo", strlen("foo"), 4);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user