Module: DIALOG_BOX
- Extended by:
- Fiddle::Importer
- Defined in:
- lib/dialog_box.rb
Constant Summary collapse
- DIALOG_BOX_FUNCTIONS_MAP =
{}
- @@dialog_box_import_done =
false- @@lib_signature =
[ 'char* get_file_dialog()' ]
Class Method Summary collapse
- .extern(signature, *opts) ⇒ Object
- .import_symbols(output_error = false) ⇒ Object
-
.load_lib(lib = nil, path = nil, output_error = false) ⇒ Object
Load native dll libary.
Class Method Details
.extern(signature, *opts) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dialog_box.rb', line 9 def self.extern(signature, *opts) symname, ctype, argtype = parse_signature(signature, @type_alias) opt = (opts) f = import_function(symname, ctype, argtype, opt[:call_type]) name = symname.gsub(/@.+/,'') DIALOG_BOX_FUNCTIONS_MAP[name] = f begin /^(.+?):(\d+)/ =~ caller.first file, line = $1, $2.to_i rescue file, line = __FILE__, __LINE__+3 end args_str="*args" module_eval(<<-EOS, file, line) def #{name}(*args, &block) DIALOG_BOX_FUNCTIONS_MAP['#{name}'].call(*args,&block) end EOS module_function(name) f end |
.import_symbols(output_error = false) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/dialog_box.rb', line 100 def self.import_symbols(output_error = false) # function @@lib_signature.each do |sig| extern sig end @@dialog_box_import_done = true end |
.load_lib(lib = nil, path = nil, output_error = false) ⇒ Object
Load native dll libary
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/dialog_box.rb', line 37 def self.load_lib(lib = nil, path = nil, output_error = false) if lib == nil && path == nil if RUBY_PLATFORM =~ /64/ # puts "You have a 64-bit Architecture ruby" if RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/ # puts "With Windows" lib, path = 'dialog_box_x64.dll', "#{__dir__}/dlls" elsif RUBY_PLATFORM =~ /linux/ || RUBY_PLATFORM =~ /cygwin/ # puts "With Linux" lib, path = 'libstb_x64.so', "#{__dir__}/dlls" elsif RUBY_PLATFORM =~ /darwin/ # puts "With macOS" else # puts "I have no idea what os are you using, so it's possible that stbimage wont't work" end elsif RUBY_PLATFORM =~ /arm/ # puts "You have a arm architecture" lib, path = 'libstb_arm.so', "#{__dir__}/dlls" elsif RUBY_PLATFORM =~ /java/ # puts "You have jruby!" else # puts "You have a 32-bit Architecture ruby" if RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/ # puts "With Windows" lib, path = 'dialog_box_x86.dll', "#{__dir__}/dlls" elsif RUBY_PLATFORM =~ /linux/ || RUBY_PLATFORM =~ /cygwin/ # puts "With Linux" lib, path = 'libstb_x86.so', "#{__dir__}/dlls" elsif RUBY_PLATFORM =~ /darwin/ # puts "With macOS" else # puts "I have no idea what os are you using, so it's possible that stbimage wont't work" end end end if path dlload (path + '/' + lib) else dlload ("#{__dir__}/#{lib}") end import_symbols(output_error) unless @@dialog_box_import_done end |