Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrapping shared variables using Rebol 3 FFI

Tags:

rebol

rebol3

Atronix Rebol 3 FFI looks pretty good in wrapping external functions, but I cannot find any references about wrapping external variables using it.

For example, Curses/NCurses library have the external variable stdscr defined in C as

extern WINDOW *stdscr;

I want to use it in my Rebol code. Ideally I want to use it as a common Rebol variable, but a read-only access (as a result of a function call, for example) would be great too.

Is it possible with Rebol 3 FFI?

I know that this practice might be considered harmful, but sometimes external libraries are written this way.

like image 304
Ivan Sukin Avatar asked Oct 20 '22 00:10

Ivan Sukin


1 Answers

You can do this with the commit. Prebuild binaries can be downloaded from here (only in development releases)

Here is the example code:

rebol []

ncurses: make library! %libncursesw.so

stdscr: make struct! compose/deep [
    [
        extern: [(ncurses) "stdscr"]
    ]
    ptr [pointer]
]

print ["stdscr:" stdscr/ptr]
close ncurses
like image 98
Shixin Zeng Avatar answered Oct 22 '22 22:10

Shixin Zeng