mirror of
https://github.com/vlang/v.git
synced 2025-09-15 07:22:27 +03:00
This is a copy/adaptation of the python example (#13105)
This commit is contained in:
parent
7c2f3e4530
commit
357ac0bb5a
4 changed files with 44 additions and 0 deletions
23
examples/call_v_from_ruby/test.rb
Normal file
23
examples/call_v_from_ruby/test.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
require 'bundler/inline'
|
||||
|
||||
gemfile do
|
||||
source 'https://rubygems.org'
|
||||
gem 'ffi'
|
||||
end
|
||||
|
||||
require 'ffi'
|
||||
|
||||
module Lib
|
||||
extend FFI::Library
|
||||
|
||||
ffi_lib File.join(File.dirname(__FILE__), 'test.so')
|
||||
|
||||
attach_function :square, [:int], :int
|
||||
attach_function :sqrt_of_sum_of_squares, [:double, :double], :double
|
||||
end
|
||||
|
||||
puts "Lib.square(10) result is #{Lib.square(10)}"
|
||||
raise 'Cannot validate V square().' unless Lib.square(10) == 100
|
||||
|
||||
raise 'Cannot validate V sqrt_of_sum_of_squares().' unless \
|
||||
Lib.sqrt_of_sum_of_squares(1.1, 2.2) == Math.sqrt(1.1*1.1 + 2.2*2.2)
|
Loading…
Add table
Add a link
Reference in a new issue