Rename init fn to be able to `require binary` directly

This commit is contained in:
Matthias Beyer 2017-01-22 16:55:45 +01:00
parent 41cacb3c78
commit 916d647a24
4 changed files with 7 additions and 31 deletions

View File

@ -5,9 +5,9 @@ module RubyImag
IMAG_INIT_FN_NAME = 'imag_ruby_initialize'
def self.setup binary_path
require 'fiddle'
require binary_path
self.core_setup binary_path
self.core_setup
self.classes_setup
end
@ -55,10 +55,7 @@ module RubyImag
]
end
def self.core_setup binary
lib = Fiddle::dlopen binary
Fiddle::Function::new(lib[RubyImag::IMAG_INIT_FN_NAME], [], Fiddle::TYPE_VOIDP).call
def self.core_setup
self.class_names.map {|n| [n, "R#{n}".to_sym ] }.each do |elem|
RubyImag.const_set elem.first, Kernel.const_get(elem.last)
end

View File

@ -41,7 +41,8 @@ pub mod storeid;
pub mod toml_utils;
#[no_mangle]
pub extern fn imag_ruby_initialize() {
#[allow(non_snake_case)]
pub extern fn Init_liblibimagruby() {
self::store::setup();
self::storeid::setup();
self::entry::setup_filelockentry();

View File

@ -1,17 +1,6 @@
#!/usr/bin/env ruby
require 'fiddle'
INIT_FN = 'imag_ruby_initialize'
for targ in %w(debug release)
begin
lib = Fiddle::dlopen "../target/#{targ}/liblibimagruby.so"
Fiddle::Function::new(lib[INIT_FN], [], Fiddle::TYPE_VOIDP).call
break;
rescue Fiddle::DLError
end
end
require "../target/debug/liblibimagruby.so"
color = true
verbose = true

View File

@ -1,17 +1,6 @@
#!/usr/bin/env ruby
require 'fiddle'
INIT_FN = 'imag_ruby_initialize'
for targ in %w(debug)
begin
lib = Fiddle::dlopen "../target/#{targ}/liblibimagruby.so"
Fiddle::Function::new(lib[INIT_FN], [], Fiddle::TYPE_VOIDP).call
break;
rescue Fiddle::DLError
end
end
require "../target/debug/liblibimagruby.so"
color = true
verbose = true