From fe669f8ce1fabd79754806f1236ad74f605c5bb3 Mon Sep 17 00:00:00 2001 From: Oli Barnett Date: Fri, 12 Jan 2024 14:59:09 +0100 Subject: [PATCH] examples: fix "call v from ruby" example for Windows and Mac (#20487) --- examples/call_v_from_ruby/test.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/examples/call_v_from_ruby/test.rb b/examples/call_v_from_ruby/test.rb index 6ea33748a..0241c7b76 100644 --- a/examples/call_v_from_ruby/test.rb +++ b/examples/call_v_from_ruby/test.rb @@ -7,10 +7,26 @@ end require 'ffi' +# extension for shared libraries varies by platform - see vlib/dl/dl.v +# get_shared_library_extension() +def shared_library_extension + if Gem.win_platform? + '.dll' + elsif RUBY_PLATFORM =~ /darwin/ # MacOS + '.dylib' + else + '.so' + end +end + module Lib extend FFI::Library - ffi_lib File.join(File.dirname(__FILE__), 'test.so') + begin + ffi_lib File.join(File.dirname(__FILE__), 'test' + shared_library_extension) + rescue LoadError + abort("No shared library test#{shared_library_extension} found. Check examples/call_v_from_ruby/README.md") + end attach_function :square, [:int], :int attach_function :sqrt_of_sum_of_squares, [:double, :double], :double -- 2.39.5