[ruby-dl] extern a global variable?

I am wrapping ncursesw for ruby.
In ncurses.h it has declared the following variable:
extern int COLORS;

I would like to access COLORS from ruby (if possible).
I have tried extern 'int COLORS' but without luck.

nm -a libncursesw.a

[snip]
00000000 B COLOR_PAIRS
00000004 B COLORS
         U curscr
         U cur_term
0000001c t default_bg
[snip]

I guess its accessable from the outside.. just how to do it?

Thanks in advance.

···

--
Simon Strandgaard

I have made some more progress.. but still I cannot access the value..

  COLORS = symbol 'COLORS'
  Int = struct ["int value"]

...

Later I then can access Curses::COLORS which gives me an PtrData instance.
After I have invoked Curses.start_color I try access the variable.

  i = Curses::Int.new(Curses::COLORS).value
  p i

It results in 0. Im not sure if this is the right way to access variables?

btw: wouldn't it be easier if one could type extern 'int COLORS' and
accomplish the same?

···

On Thu, 20 Jan 2005 21:22:58 +0100, Simon Strandgaard <neoneye@gmail.com> wrote:

I am wrapping ncursesw for ruby.
In ncurses.h it has declared the following variable:
extern int COLORS;

I would like to access COLORS from ruby (if possible).
I have tried extern 'int COLORS' but without luck.

> nm -a libncursesw.a
[snip]
00000000 B COLOR_PAIRS
00000004 B COLORS
         U curscr
         U cur_term
0000001c t default_bg
[snip]

I guess its accessable from the outside.. just how to do it?

--
Simon Strandgaard

Simon Strandgaard wrote:

I am wrapping ncursesw for ruby. In ncurses.h it has declared the following variable:
extern int COLORS;

I would like to access COLORS from ruby (if possible).
I have tried extern 'int COLORS' but without luck.

Does this work?

module MyLib
    extend DL::Importable
    dlload "ncurses.so"

    Colors = symbol "COLORS"
end

No, it seems to return a PtrData instance.

I have made something that seems to work.. feels ackward though.
I can now access Curses.COLORS and Curses.ESCDELAY.

module Curses
  extend DL::Importable
  dlload 'libncursesw.so'

  Int = struct ["int value"]
  COLORS_PTR = symbol 'COLORS'
  ESCDELAY_PTR = symbol 'ESCDELAY'
  def self.COLORS
    Int.new(COLORS_PTR).value
  end
  def self.ESCDELAY
    Int.new(ESCDELAY_PTR).value
  end
end

Im curious to if this can be done smarter?

···

On Fri, 21 Jan 2005 07:10:58 +0900, Florian Gross <flgr@ccan.de> wrote:

Simon Strandgaard wrote:

> I am wrapping ncursesw for ruby.
> In ncurses.h it has declared the following variable:
> extern int COLORS;
>
> I would like to access COLORS from ruby (if possible).
> I have tried extern 'int COLORS' but without luck.

Does this work?

module MyLib
    extend DL::Importable
    dlload "ncurses.so"

    Colors = symbol "COLORS"
end

--
Simon Strandgaard