module TD::Api::Dl

Public Instance Methods

find_lib() click to toggle source
# File lib/tdlib/api.rb, line 63
def find_lib
  file_name = "libtdjson.#{lib_extension}"
  lib_path =
    if TD.config.lib_path
      TD.config.lib_path
    elsif defined?(Rails) && File.exist?(Rails.root.join('vendor', file_name))
      Rails.root.join('vendor')
    end
  full_path = File.join(lib_path.to_s, file_name)
  ffi_lib full_path
  full_path
rescue LoadError
  ffi_lib 'tdjson'
  ffi_libraries.first.name
end
lib_extension() click to toggle source
# File lib/tdlib/api.rb, line 79
def lib_extension
  case os
  when :windows then 'dll'
  when :macos then 'dylib'
  when :linux then 'so'
  else raise "#{os} OS is not supported"
  end
end
method_missing(method_name, *args) click to toggle source
# File lib/tdlib/api.rb, line 43
def method_missing(method_name, *args)
  @mutex.synchronize do
    return public_send(method_name, *args) if respond_to?(method_name)

    find_lib

    attach_function :td_json_client_create, [], :pointer
    attach_function :td_json_client_receive, [:pointer, :double], :string, blocking: true
    attach_function :td_json_client_send, [:pointer, :string], :pointer, blocking: true
    attach_function :td_json_client_execute, [:pointer, :string], :string, blocking: true
    attach_function :td_json_client_destroy, [:pointer], :void
    attach_function :td_set_log_file_path, [:string], :int
    attach_function :td_set_log_max_file_size, [:long_long], :void
    attach_function :td_set_log_verbosity_level, [:int], :void

    undef method_missing
    public_send(method_name, *args)
  end
end
os() click to toggle source
# File lib/tdlib/api.rb, line 88
def os
  host_os = RbConfig::CONFIG['host_os']
  case host_os
  when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
    :windows
  when /darwin|mac os/
    :macos
  when /linux/
    :linux
  when /solaris|bsd/
    :unix
  else
    raise "Unknown os: #{host_os.inspect}"
  end
end