gforth-raylib icon indicating copy to clipboard operation
gforth-raylib copied to clipboard

Assistance in porting the binding

Open rigobert9 opened this issue 2 years ago • 3 comments

Hello, I'm trying to update the bindings to the last version; could you share the .i and -fsi.c files? I don't have any experience in making that kind of bindings, and I'm a bit confused by the whole thing. Otherwise, got your original binding working; thank you so much for your hard work on this!

rigobert9 avatar Jun 09 '23 11:06 rigobert9

I don't have the files anymore for that.

https://gforth.org/manual/Automated-interface-generation-using-SWIG.html

But it should be easy to generate.

Honestly, that method isn't worth it, what I'd do is this.

https://github.com/raysan5/raylib/tree/master/parser

Whats nice is iirc there are only two types: functions that return a struct, and functions that don't. The only problem with the former is you need C code to convert it to return a pointer instead since gforth can't handle returning structs.

I believe it'd be easier to just write a script that takes (maybe) json from the parser with the function signatures and converts them into the gforth declarations. The only thing the parser needs to watch is the return value, which, if it's a struct then you just automatically have it put the C code in to convert it to a pointer return.

I haven't had time to do it but eventually I will if someone else doesn't. 3.5 is perfectly workable for using Raylib at the moment at least.

The script method will help us track the latest raylib much easier too, and I suppose it could be in any language.

ArnautDaniel avatar Jun 09 '23 12:06 ArnautDaniel

Thank you very much for your quick response. I didn't think of that, but doing something like this seems worthwhile to me, I'll probably try to do it; thanks for the idea. For the smaller structures used, do you know if it is possible to return multiple values (on the stack) or to use different pattern other than a pointer to follow? I don't know anything about the lib or even the classic things that are done with it, so I'll discover most of it while doing the binding.

rigobert9 avatar Jun 09 '23 13:06 rigobert9

Hmm, I'm not sure on returning multiple values. It might be possible to have the word itself put the structure items on the stack by default so you don't have to do it.

Unfortunately, when we do the pointer method it gets placed on the heap, so now you have to free that memory when you're done with it, which you don't have to do in regular Raylib. So there might be a better way to do that.

ArnautDaniel avatar Jun 09 '23 15:06 ArnautDaniel