From 48d704faed2dc5b0d03ed74aab820b92a43ab410 Mon Sep 17 00:00:00 2001 From: zach Date: Mon, 25 Nov 2024 10:00:12 -0800 Subject: [PATCH] feat: enable host function namespaces --- lib/extism/wasm.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/extism/wasm.rb b/lib/extism/wasm.rb index 1a68f7d..fea2234 100644 --- a/lib/extism/wasm.rb +++ b/lib/extism/wasm.rb @@ -70,10 +70,12 @@ class Function # @param params [Array[Extism::ValType]] An array of val types matching the import's params # @param returns [Array[Extism::ValType]] An array of val types matching the import returns # @param func_proc [Proc] A proc that will be executed when the host function is executed + # @param namespace [String] The Wasm namespace that will be used for the function # @param user_data [Object] Any reference to object you want to be passed back to you when the func is invoked # @param on_free [Proc] A proc triggered when this function is freed by the runtime. Not guaranteed to trigger. - def initialize(name, params, returns, func_proc, user_data: nil, on_free: nil) + def initialize(name, params, returns, func_proc, namespace: "extism:host/user", user_data: nil, on_free: nil) @name = name + @namespace = namespace @params = params @returns = returns @func = func_proc @@ -93,6 +95,7 @@ def pointer returns = LibExtism.from_int_array(@returns) @_pointer = LibExtism.extism_function_new(@name, args, @params.length, returns, @returns.length, c_func, free, nil) + LibExtism.extism_function_set_namespace(@_pointer, @namespace) $FUNCTIONS[object_id] = { function: @_pointer} ObjectSpace.define_finalizer(self, $FREE_FUNCTION) return @_pointer