nostrscript: add a helper function

This commit is contained in:
William Casarin
2023-07-03 16:59:50 -07:00
parent a6cbf50def
commit 30e33a01c1
9 changed files with 98 additions and 3 deletions

View File

@@ -97,6 +97,23 @@ static int nostr_log(struct wasm_interp *interp) {
return 1;
}
static int nostr_set_bool(struct wasm_interp *interp) {
struct val *params = NULL;
const u16 *setting;
u32 val, len;
if (!get_params(interp, &params, 3) || params == NULL)
return 0;
if (!mem_ptr_str(interp, params[0].num.i32, (const char**)&setting))
return 0;
len = params[1].num.i32;
val = params[2].num.i32 > 0 ? 1 : 0;
return nscript_set_bool(interp, setting, len, val);
}
static int nostr_pool_send_to(struct wasm_interp *interp) {
struct val *params = NULL;
const u16 *req, *to;
@@ -149,6 +166,7 @@ static struct builtin nscript_builtins[] = {
{ .name = "nostr_log", .fn = nostr_log },
{ .name = "nostr_cmd", .fn = nostr_cmd },
{ .name = "nostr_pool_send_to", .fn = nostr_pool_send_to },
{ .name = "nostr_set_bool", .fn = nostr_set_bool },
{ .name = "abort", .fn = nscript_abort },
};

View File

@@ -18,6 +18,7 @@
int nscript_load(struct wasm_parser *p, struct wasm_interp *interp, unsigned char *wasm, unsigned long len);
int nscript_nostr_cmd(struct wasm_interp *interp, int, void*, int);
int nscript_pool_send_to(struct wasm_interp *interp, const u16*, int, const u16 *, int);
int nscript_set_bool(struct wasm_interp *interp, const u16*, int, int);
#endif /* nostrscript_h */