Search code examples
ccrystal-lang

Binding C to Crystal: preprocessor directives


I'm working with the crt.cr Crystal shard, which binds ncurses. It's lacking some things I want, like mvhline(). So I'm adding the things I want.

One thing I want is is ncurses alternative character sheet, so I can make nice boxes.

As far as I can tell, this is pretty dang hard (but I'm not an expert in either Crystal or C). From what I can tell, the alternative character sheet characters are all unsigned chars, defined by the preprocessor.

Can someone explain how I can get access to the alternative character sheet characters?


Solution

  • You cannot access things that are only in C header files (and things that are done through the preprocessor) in a shared library file, because they simply aren't put there.

    Since Crystal only binds to a shared library file, there is no option other than manually (sometimes automatically) duplicating these as constants in Crystal code.