Skip to content

Commit

Permalink
Fix config initializer
Browse files Browse the repository at this point in the history
Closes #22
  • Loading branch information
bhelx committed Jul 19, 2024
1 parent 21c196f commit 1aff558
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/extism/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def initialize(wasm, environment: nil, functions: [], wasi: false, config: nil)
end
$PLUGINS[object_id] = { plugin: @plugin }
ObjectSpace.define_finalizer(self, $FREE_PLUGIN)
return unless !config.nil? and @plugin.null?
return if config.nil? or @plugin.null?

s = JSON.generate(config)
ptr = FFI::MemoryPointer.from_string(s)
Expand Down
5 changes: 4 additions & 1 deletion test/test_extism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_that_it_has_a_version_number
end

def test_plugin_call
plugin = Extism::Plugin.new(vowels_manifest)
plugin = Extism::Plugin.new(vowels_manifest, config: { vowels: 'aeiouyAEIOUY' })
res = JSON.parse(plugin.call('count_vowels', 'this is a test'))
assert_equal res['count'], 4
res = JSON.parse(plugin.call('count_vowels', 'this is a test again'))
Expand All @@ -73,6 +73,9 @@ def test_plugin_call
assert_equal res['count'], 6
res = JSON.parse(plugin.call('count_vowels', '🌎hello🌎world🌎'))
assert_equal res['count'], 3
res = JSON.parse(plugin.call('count_vowels', 'does y count?'))
assert_equal res['count'], 5
assert_equal res['vowels'], 'aeiouyAEIOUY'
end

def test_can_free_plugin
Expand Down

0 comments on commit 1aff558

Please sign in to comment.