<commit_before>#
# Exploratory program to see what kind of method_missing we would need in a
# module. In the end, this code would have to be generated by the Builder,
# or be provided by a mixin.
#

$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
require 'girffi'
require 'girffi/builder'

module GObject
  module Lib
    extend FFI::Library
    ffi_lib "gobject-2.0"
    # TODO: Genereate these
    callback :Callback, [], :void
    callback :ClosureNotify, [:pointer, :pointer], :void
    enum :ConnectFlags, [:AFTER, (1<<0), :SWAPPED, (1<<1)]
  end

  def self.method_missing method, *arguments
    @@builder ||= GirFFI::Builder.new
    go = @@builder.function_introspection_data "GObject", method.to_s

    # TODO: Unwind stack of raised NoMethodError to get correct error
    # message.
    return super if go.nil?
    return super if go.type != :function

    @@builder.attach_ffi_function Lib, go

    code = @@builder.function_definition go

    (class << self; self; end).class_eval code

    self.send method, *arguments
  end
end


module Gtk
  module Lib
    extend FFI::Library
    ffi_lib "gtk-x11-2.0"
    # TODO: Genereate these
    enum :GtkWindowType, [:GTK_WINDOW_TOPLEVEL, :GTK_WINDOW_POPUP]
    attach_function :gtk_window_new, [:GtkWindowType], :pointer
  end

  def self.method_missing method, *arguments
    @@builder ||= GirFFI::Builder.new
    go = @@builder.function_introspection_data "Gtk", method.to_s

    # TODO: Unwind stack of raised NoMethodError to get correct error
    # message.
    return super if go.nil?
    return super if go.type != :function

    @@builder.attach_ffi_function Lib, go

    code = @@builder.function_definition go

    (class << self; self; end).class_eval code

    self.send method, *arguments
  end<commit_msg>Don't forget to send the block in method_missing.<commit_after>#
# Exploratory program to see what kind of method_missing we would need in a
# module. In the end, this code would have to be generated by the Builder,
# or be provided by a mixin.
#

$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
require 'girffi'
require 'girffi/builder'

module GObject
  module Lib
    extend FFI::Library
    ffi_lib "gobject-2.0"
    # TODO: Genereate these
    CALLBACKS = []
    callback :Callback, [], :void
    callback :ClosureNotify, [:pointer, :pointer], :void
    enum :ConnectFlags, [:AFTER, (1<<0), :SWAPPED, (1<<1)]
  end

  def self.method_missing method, *arguments, &block
    @@builder ||= GirFFI::Builder.new
    go = @@builder.function_introspection_data "GObject", method.to_s

    # TODO: Unwind stack of raised NoMethodError to get correct error
    # message.
    return super if go.nil?
    return super if go.type != :function

    @@builder.attach_ffi_function Lib, go

    code = @@builder.function_definition go

    (class << self; self; end).class_eval code

    if block.nil?
      self.send method, *arguments
    else
      self.send method, *arguments, &block
    end
  end
end


module Gtk
  module Lib
    extend FFI::Library
    ffi_lib "gtk-x11-2.0"
    # TODO: Genereate these
    enum :GtkWindowType, [:GTK_WINDOW_TOPLEVEL, :GTK_WINDOW_POPUP]
    attach_function :gtk_window_new, [:GtkWindowType], :pointer
  end

  def self.method_missing method, *arguments
    @@builder ||= GirFFI::Builder.new
    go = @@builder.function_introspection_data "Gtk", method.to_s

    # TODO: Unwind stack of raised NoMethodError to get correct error
    # message.
    return super if go.nil?
    return super if go.type != :function

    @@builder.attach_ffi_function Lib, go

    code = @@builder.function_definition go

    (class << self; self; end).class_eval code

    self.send method, *arguments
  end
{'fraction_non_alphanumeric': 0.1033091202582728, 'fraction_numerical': 0.0053806833467850415, 'mean_word_length': 3.5286236297198537, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '761537', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1195, 'n_words': 372}