Class: GObjectIntrospection::Loader::VirtualFunctionImplementor
- Inherits:
-
Object
- Object
- GObjectIntrospection::Loader::VirtualFunctionImplementor
- Defined in:
- lib/gobject-introspection/loader.rb
Instance Method Summary collapse
- #implement(implementor_gtype, name) ⇒ Object
-
#initialize(loader_class, gtype_prefix, infos) ⇒ VirtualFunctionImplementor
constructor
A new instance of VirtualFunctionImplementor.
Constructor Details
#initialize(loader_class, gtype_prefix, infos) ⇒ VirtualFunctionImplementor
Returns a new instance of VirtualFunctionImplementor.
868 869 870 871 872 873 874 875 876 877 878 |
# File 'lib/gobject-introspection/loader.rb', line 868 def initialize(loader_class, gtype_prefix, infos) @loader_class = loader_class @gtype_prefix = gtype_prefix @infos = {} prefix = GLib::VIRTUAL_FUNCTION_IMPLEMENTATION_PREFIX infos.each do |info| name = info.name @infos[:"#{prefix}#{name}"] = info @infos[:"#{prefix}#{gtype_prefix}_#{name}"] = info end end |
Instance Method Details
#implement(implementor_gtype, name) ⇒ Object
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 |
# File 'lib/gobject-introspection/loader.rb', line 880 def implement(implementor_gtype, name) info = @infos[name] return false if info.nil? container = info.container vtable_gtype = container.gtype if container.respond_to?(:class_struct) struct = container.class_struct # This is for "super" in "virtual_do_XXX". parent_gtype = implementor_gtype.parent parent_class = parent_gtype.to_class invoker = Invoker.new(info, name, "#{parent_class.name}\##{name}") parent_vfunc_callable = Module.new parent_vfunc_callable.define_method(name) do |*args, &block| invoker.invoke(self, args, block, implementor_gtype: parent_gtype) end # If we use implementor_gtype.class.include here, # GLib::Instantiatable.include calls this method # recursively. We don't need to call any hook for this # method. So we use the original Module.include here. Module.method(:include).unbind.bind_call(implementor_gtype.to_class, parent_vfunc_callable) else return false unless implementor_gtype.type_is_a?(vtable_gtype) struct = container.iface_struct end field = struct.find_field(info.name) @loader_class.implement_virtual_function(field, implementor_gtype, vtable_gtype, name.to_s) true end |