Is there any info and tutorials on wrapping and binding things for freebasic?

New to FreeBASIC? Post your questions here.
Post Reply
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Is there any info and tutorials on wrapping and binding things for freebasic?

Post by Boromir »

Is there any info and tutorials on wrapping and binding things for use in Freebasic? This is something I really want to learn but I have no idea where to start. Specifically, I want to wrap basic sections of the c++ steamworks api to fb though I probably couldn't do that right off, I have to start learning some time.
St_W
Posts: 1619
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Is there any info and tutorials on wrapping and binding things for freebasic?

Post by St_W »

A C++ API is hard or impossible to access directly from FreeBasic; If the library doesn't provide a C API it's probably better to write a C wrapper in C++ and create binding for that wrapper.

These pages in the wiki contain some general information:
http://freebasic.net/wiki/wikka.php?wak ... ngCreation
http://freebasic.net/wiki/wikka.php?wak ... StyleGuide

Unfortunately a tutorial / step-by-step guide is not available at the moment:
http://freebasic.net/wiki/wikka.php?wak ... lateHeader

I'd start with fbfrog (https://github.com/dkl/fbfrog) and correct errors manually afterwards.
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: Is there any info and tutorials on wrapping and binding things for freebasic?

Post by Boromir »

--deleted--
Does this mean It already has C support?
Last edited by Boromir on May 21, 2017 23:10, edited 2 times in total.
St_W
Posts: 1619
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Is there any info and tutorials on wrapping and binding things for freebasic?

Post by St_W »

Boromir wrote:Does this mean It already has C support?
Yes.

That makes using the library a lot easier as you can use it directly from FreeBasic without any wrappers (you "just" need to translate the headers (or: the parts of it that you need))

But you may run still into problems if they haven't implemented it for all the functionality accessible from C++ (in case you need such a function). Sometimes when both C and C++ APIs are available the C API only provides limited functionality compared to the C++ API. As your library and its documentation aren't publicly available, I could not take a look on it.
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: Is there any info and tutorials on wrapping and binding things for freebasic?

Post by Boromir »

I got fbfrog and attempted it on steamworks.

cmd executed
"fbfrog steam/steam_api.h"

it gets stuck after printing
[ 1/23] linux-x86

It works fine with the headers in the test folder.
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: Is there any info and tutorials on wrapping and binding things for freebasic?

Post by dkl »

Hi,

looks like a bug in fbfrog, I think it hangs on the C++ code in steam_api.h.

The "flat C-style API" seems to be in steam_api_flat.h. It still contains some C++ things which makes fbfrog choke, but nevertheless, I got fairly good results by doing this:
fbfrog steam/steam_api_flat.h -define S_API -define class -define bool _Bool
Unfortunately, there are too many types and enums missing, it can't be used as-is (not even in a C program). I guess it would be possible to work-around that by defining the missing types and enums manually based on the C++ headers, and get a complete header and ultimately a compatible binding, but that would surely be a lot of work.
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: Is there any info and tutorials on wrapping and binding things for freebasic?

Post by Boromir »

D.J.Peters wrote:Here is the C++ to C API wrapper https://github.com/rlabrecque/CSteamworks
Joshy
Yeah I saw this too but then I saw the note about having built in flat C-style API and I thought it was preferable.
I tried fbfrog on this and it created a file full of TODOs. I assume I'm doing something in the wrong order because I don't know which .h files to feed fbfrog. I used "steam_api_c.h" in the wrapper folder but at looking at the generated .bi I see it is referencing an in existent "CSteamworks.bi"
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Is there any info and tutorials on wrapping and binding things for freebasic?

Post by D.J.Peters »

Looks like CSteamworks is for advanced users
you have to build the C++ wrapper self at first
and than build from the *.h files the right *.bi files.

Is there no official C API in the Steamworks SDK ?

Joshy
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: Is there any info and tutorials on wrapping and binding things for freebasic?

Post by Boromir »

D.J.Peters wrote:You have to build the C++ wrapper self at first
I did build it. It was a matter of running the python script.
D.J.Peters wrote: and than build from the *.h files the right *.bi files.
That's when it made me a bi file with a list of TODO's
D.J.Peters wrote: Is there no official C API in the Steamworks SDK ?
It does have the flat C-style api
St_W
Posts: 1619
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Is there any info and tutorials on wrapping and binding things for freebasic?

Post by St_W »

Don't build a C++ wrapper yourself if not absolutely necessary - and it shouldn't as the flat-api is already such a wrapper. That would be just useless work and a possible source for errors.

You don't seem to be aware that very likely manual fixes and manual code translation/writing will be required. If you are not willing or able to do that it probably won't work.
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: Is there any info and tutorials on wrapping and binding things for freebasic?

Post by Boromir »

St_W wrote:You don't seem to be aware that very likely manual fixes and manual code translation/writing will be required. If you are not willing or able to do that it probably won't work.
I understand it's a lot of work and I most certainly am not skilled in this. But I must start somewhere though maybe do something simpler before tackling this.
St_W
Posts: 1619
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Is there any info and tutorials on wrapping and binding things for freebasic?

Post by St_W »

Boromir wrote:But I must start somewhere though maybe do something simpler before tackling this.
Probably you will need only a few methods from the API at the beginning. So to get familiar you could try to pick only a few function definitions and write FreeBasic headers and a sample (test-)application for those. Maybe you can also use parts of automatically generated code by fbfrog or similar tools. If you run into a problem for a concrete method don't hesitate do ask here, but don't forget to include the original C declarations and describe the problem accurately.
Post Reply