@@ -58,9 +58,7 @@ pub fn cancelHandle(self: *Self) CancelHandle {
58
58
return .{ .handle = ptr };
59
59
}
60
60
61
- /// Call a function with the given input
62
- pub fn call (self : * Self , function_name : []const u8 , input : []const u8 ) ! []const u8 {
63
- const res = c .extism_plugin_call (self .ptr , function_name .ptr , input .ptr , @as (u64 , input .len ));
61
+ fn handleCall (self : * Self , res : i32 ) ! []const u8 {
64
62
if (res != 0 ) {
65
63
const err_c = c .extism_plugin_error (self .ptr );
66
64
const err = std .mem .span (err_c );
@@ -80,6 +78,19 @@ pub fn call(self: *Self, function_name: []const u8, input: []const u8) ![]const
80
78
}
81
79
return "" ;
82
80
}
81
+
82
+ /// Call a function with the given input
83
+ pub fn call (self : * Self , function_name : []const u8 , input : []const u8 ) ! []const u8 {
84
+ const res = c .extism_plugin_call (self .ptr , function_name .ptr , input .ptr , @as (u64 , input .len ));
85
+ return self .handleCall (res );
86
+ }
87
+
88
+ /// Call a function with the given input and host context
89
+ pub fn callWithContext (self : * Self , function_name : []const u8 , input : []const u8 , host_context : * anyopaque ) ! []const u8 {
90
+ const res = c .extism_plugin_call_with_host_context (self .ptr , function_name .ptr , input .ptr , @as (u64 , input .len ), host_context );
91
+ return self .handleCall (res );
92
+ }
93
+
83
94
/// Set configuration values
84
95
pub fn setConfig (self : * Self , allocator : std.mem.Allocator , config : std .json .ArrayHashMap ([]const u8 )) ! void {
85
96
const config_json = try std .json .stringifyAlloc (allocator , config , .{ .emit_null_optional_fields = false });
0 commit comments