Skip to content

Commit

Permalink
add setError
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmd-azeez committed Nov 22, 2023
1 parent 85c4d07 commit 4f8cef6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ pub const Plugin = struct {
extism.output_set(offset, c_len);
}

pub fn setErrorMemory(self: Plugin, mem: Memory) void {
_ = self; // to make the interface consistent
extism.error_set(mem.offset);
}

pub fn setError(self: Plugin, data: []const u8) void {
_ = self; // to make the interface consistent
const c_len = @as(u64, data.len);
const offset = extism.alloc(c_len);
const memory = Memory.init(offset, c_len);
defer memory.free();
memory.store(data);
extism.error_set(offset);
}

/// IMPORTANT: it's the caller's responsibility to free the returned string
pub fn getConfig(self: Plugin, key: []const u8) !?[]u8 {
const key_mem = Memory.allocateBytes(key);
Expand Down

0 comments on commit 4f8cef6

Please sign in to comment.