Combining common variables using Rebol 3 FFI

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

For example, the Curses / NCurses library has an 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 general Rebol variable, but access to constant access (as a result of calling a function, for example) will also be great.

Is this possible with Rebol 3 FFI?

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

+5
source share
1 answer

You can do this with commit . Pre-build binaries can be downloaded from here (only in development releases)

Here is a sample code:

 rebol [] ncurses: make library! %libncursesw.so stdscr: make struct! compose/deep [ [ extern: [(ncurses) "stdscr"] ] ptr [pointer] ] print ["stdscr:" stdscr/ptr] close ncurses 
+3
source

Source: https://habr.com/ru/post/1233515/


All Articles