Class: QML::PluginLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/qml/plugin_loader.rb,
ext/qml/plugin_loader.c

Overview

PluginLoader loads Qt C++ plugins and enables you to use your Qt C++ codes from Ruby easily.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ PluginLoader #initialize(dir, libname) ⇒ PluginLoader

Returns a new instance of PluginLoader.

Overloads:

  • #initialize(path) ⇒ PluginLoader

    Examples:

    loader = QML::PluginLoader.new('path/to/libhoge.dylib')

    Parameters:

    • path (String|Pathname)

      the library path (may be platform-dependent).

  • #initialize(dir, libname) ⇒ PluginLoader

    Examples:

    loader = QML::PluginLoader.new('path/to', 'hoge')

    Parameters:

    • dir (String|Pathname)

      the library directory.

    • libname (String)

      the platform-independent library name.



18
19
20
21
# File 'lib/qml/plugin_loader.rb', line 18

def initialize(path, libname = nil)
  path = Pathname(path) + self.class.lib_filename(libname) if libname
  initialize_impl(path.to_s)
end

Class Method Details

.lib_filename(libname) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/qml/plugin_loader.rb', line 23

def self.lib_filename(libname)
  case
  when Platform::windows?
    "#{libname}.dll"
  when Platform::mac?
    "lib#{libname}.dylib"
  else
    "lib#{libname}.so"
  end
end

Instance Method Details

#instanceQML::JSObject

Loads the plugin and returns the instance of the plugin.

Returns:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'ext/qml/plugin_loader.c', line 46

static VALUE plugin_loader_instance(VALUE self) {
    qmlbind_plugin plugin = rbqml_get_plugin(self);

    qmlbind_string qmlerror = qmlbind_plugin_get_error_string(plugin);
    if (qmlerror) {
        VALUE errorStr = rb_enc_str_new(qmlbind_string_get_chars(qmlerror), qmlbind_string_get_length(qmlerror), rb_utf8_encoding());
        qmlbind_string_release(qmlerror);

        VALUE error = rb_funcall(cPluginError, rb_intern("new"), 1, errorStr);
        rb_exc_raise(error);
    }

    qmlbind_value loaded = qmlbind_plugin_get_instance(plugin, rbqml_get_engine(rbqml_engine));
    return rbqml_to_ruby(loaded);
}