Skip to content

Commit fe669f8

Browse files
authored
examples: fix "call v from ruby" example for Windows and Mac (#20487)
1 parent f1fdc9c commit fe669f8

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

examples/call_v_from_ruby/test.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,26 @@
77

88
require 'ffi'
99

10+
# extension for shared libraries varies by platform - see vlib/dl/dl.v
11+
# get_shared_library_extension()
12+
def shared_library_extension
13+
if Gem.win_platform?
14+
'.dll'
15+
elsif RUBY_PLATFORM =~ /darwin/ # MacOS
16+
'.dylib'
17+
else
18+
'.so'
19+
end
20+
end
21+
1022
module Lib
1123
extend FFI::Library
1224

13-
ffi_lib File.join(File.dirname(__FILE__), 'test.so')
25+
begin
26+
ffi_lib File.join(File.dirname(__FILE__), 'test' + shared_library_extension)
27+
rescue LoadError
28+
abort("No shared library test#{shared_library_extension} found. Check examples/call_v_from_ruby/README.md")
29+
end
1430

1531
attach_function :square, [:int], :int
1632
attach_function :sqrt_of_sum_of_squares, [:double, :double], :double

0 commit comments

Comments
 (0)