I’ve been interested in using Crystal for some Linux framebuffer work. The current problem I have is binding to C.
The ioctl definitions for manipulating the framebuffer aren’t located in a “libname” library, but rather a header file called “fb.h”.
This is problematic, I don’t know how I could bind a simple header file to Crystal. Is it possible? How could it be done?
Is it in libc? If so, just putting them under any
lib LibFoo will work. Though if it’s in libc we usually put it in
I can see that most of the contents of the file are constants. And that you’re thinking in the right direction.
But yes, you can’t bind such things. Crystal doesn’t attempt to understand header files.
Only functions are exported to libs, and Crystal can bind to those.
You just have to create a Crystal file which has copies of all those definitions.
https://github.com/crystal-lang/crystal_lib does that automatically.
Okay. I’ll see what I can do with that.
I’m not quite sure what you mean by “need”. Get the functionality somehow?
I’ve gotten the C library into my program and I defined a “fun ioctl” that might work:
fun ioctl(fd : Int32, command : Int32)
fb = File.open("/dev/fb0", mode = "r")
No complaints when I compile it, and no errors when I run it. I’m not sure if I’ve actually “solved” anything though.
*Sorry for the annoying questions.