Skip to content

feat: enable host function namespaces, add CompiledPlugin #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ group :development do
gem 'debug'
gem 'minitest', '~> 5.20.0'
gem 'rufo', '~> 0.13.0'
gem 'yard', '~> 0.9.28'
gem 'yard', '~> 0.9.36'
end
4 changes: 4 additions & 0 deletions lib/extism/libextism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ class ExtismFunction < FFI::Struct
attach_function :extism_function_free, [:pointer], :void
attach_function :extism_function_set_namespace, %i[pointer string], :void
attach_function :extism_plugin_new, %i[pointer ExtismSize pointer ExtismSize bool pointer], :pointer
attach_function :extism_plugin_new_from_compiled, %i[pointer pointer], :pointer
attach_function :extism_compiled_plugin_new, %i[pointer ExtismSize pointer ExtismSize bool pointer], :pointer
attach_function :extism_plugin_new_error_free, [:pointer], :void
attach_function :extism_plugin_free, [:pointer], :void
attach_function :extism_compiled_plugin_free, [:pointer], :void
attach_function :extism_plugin_cancel_handle, [:pointer], :pointer
attach_function :extism_plugin_cancel, [:pointer], :bool
attach_function :extism_plugin_config, %i[pointer pointer ExtismSize], :bool
attach_function :extism_plugin_function_exists, %i[pointer string], :bool
attach_function :extism_plugin_call, %i[pointer string pointer ExtismSize], :int32
attach_function :extism_plugin_call_with_host_context, %i[pointer string pointer ExtismSize pointer], :int32
attach_function :extism_error, [:pointer], :string
attach_function :extism_plugin_error, [:pointer], :string
attach_function :extism_plugin_output_length, [:pointer], :ExtismSize
Expand Down
5 changes: 4 additions & 1 deletion lib/extism/wasm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading