Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am facing with interfacing with C libraries in this period (I am writing a <a href="https://github.com/ProGNOMmers/gtop" rel="nofollow">wrapper for libgtop</a>), and I choosed to use <a href="https://github.com/ffi/ffi" rel="nofollow">ffi</a>, which is <a href="https://github.com/ffi/ffi/wiki" rel="nofollow">quite well documented</a> (although the documentation sometimes is a bit outdated) and above all its mailing list is full of people who give you an helping hand when you are in trouble.</p> <p>So I propose you a solution which uses ffi:</p> <pre><code>require 'ffi' module LibX11 extend FFI::Library ffi_lib 'libX11.so.6' # Display *XkbOpenDisplay (char *display_name, int *event_rtrn, int *error_rtrn, int *major_in_out, int *minor_in_out, int *reason_rtrn) attach_function :XkbOpenDisplay, [:pointer, :pointer, :pointer, :pointer, :pointer, :pointer], :pointer end </code></pre> <p>Then you have to describe the <code>Display</code> struct layout, like written <a href="https://github.com/ffi/ffi/wiki/Structs" rel="nofollow">here</a>:</p> <pre><code>class Display &lt; FFI::Struct layout :value, :double, :other_value, :char, ... end </code></pre> <p>And then you do something like this:</p> <pre><code>p1 = FFI::MemoryPointer.new(:char) p2 = FFI::MemoryPointer.new(:int) p3 = FFI::MemoryPointer.new(:int) p4 = FFI::MemoryPointer.new(:int) p5 = FFI::MemoryPointer.new(:int) p6 = FFI::MemoryPointer.new(:int) # write to pointer if needed, otherwise it is a null pointer # p1.write_char('a') # p2.write_int(1) # ... struct_pointer = LibX11.XkbOpenDisplay(p1, p2, p3, p4, p5, p6) # read the struct struct = Display.new(display_struct_pointer) p Hash[ s.members.map { |m| [ m, s[m] ] } ] </code></pre> <p>I didn't tested the code, but it should be roughly correct. Let me now if it isn't.</p> <hr> <p>After some research about DL on ruby 2.0 I found that it is deprecated and replaced with fiddle, you would consider to use it rather than DL if you can't use FFI. Fiddle seems to be available for ruby 1.9.3 and 1.9.2 too</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload