raylib vx.x headers built with type vs constructor

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
Axle
Posts: 41
Joined: May 31, 2022 6:49
Location: Australia

raylib vx.x headers built with type vs constructor

Post by Axle »

Hi all

A question for anyone is familiar with building the raylib.bi header for FB, or has built the headers...

I am currently creating the headers for raylib + extras as well as raygui using fbfrog.
I am using previous version binders as well as the v4.0 raylib.bi as guides to check that I am creating them correctly.
Some are using type and some have used constructor for the C struc conversions.
Examples from raylib:

Code: Select all

C Source.
typedef struct Vector2 {
    float x;                // Vector x component
    float y;                // Vector y component
} Vector2;

Code: Select all

fbfrog output.
type Vector2
	x as single                 ' Vector x component
	y as single                 ' Vector y component
end type

Code: Select all

Some FB rayib headers.
type Vector2
	x as single
	y as single
	declare constructor()
	declare constructor(x as single, y as single)
end type

constructor Vector2(x as single, y as single)
	this.x = x
	this.y = y
end constructor

constructor Vector2()
end constructor
I am wondering what the pros and cons are between the use of type and constructor in the context of raylib?
And is it OK using the default struct to type conversion from fbfrog in the same way as the FBC official .\inc\raylib.bi?

Axle
fxm
Moderator
Posts: 11210
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: raylib vx.x headers built with type vs constructor

Post by fxm »

Note regardless of raylib (because no response from its users)

- For a Type with only simple numeric data members, defining constructors does not add any functionality to the Type.
- This only introduces differences in allowed syntax for construction.
- However, a common syntax for construction is allowed by both structures.

Construction syntax common to both Type structures:
  • type [ <Vector2> ] ( valx, valy )

    for examples:
    • dim as Vector2 v [ = type [ <Vector2> ] ( valx, valy ) ]
      v = type [ <Vector2> ] ( valx, valy )

Code: Select all

type Vector2
	x as single
	y as single
end type

dim as Vector2 va                        ' Common syntax
'dim as Vector2 vb = type()              ' Non OK
'dim as Vector2 vc = Vector2()           ' Non OK
'dim as Vector2 vd = type<Vector2>()     ' Non OK

dim as Vector2 ve = (1, 2)               ' OK
dim as Vector2 vf = type(1, 2)           ' Common syntax
'dim as Vector2 vg = Vector2(1, 2)       ' Non OK
dim as Vector2 vh = type<Vector2>(1, 2)  ' Common syntax

va = type(3, 4)                          ' Common syntax
'vf = Vector2(3, 4)                      ' Non OK
vh = type<Vector2>(3, 4)                 ' Common syntax

Code: Select all

type Vector2
	x as single
	y as single
	declare constructor()
	declare constructor(byval x as single, byval y as single)
end type

constructor Vector2()
end constructor

constructor Vector2(byval x as single, byval y as single)
	this.x = x
	this.y = y
end constructor

dim as Vector2 va                        ' Common syntax
dim as Vector2 vb = type()               ' OK
dim as Vector2 vc = Vector2()            ' OK
dim as Vector2 vd = type<Vector2>()      ' OK

'dim as Vector2 ve = (1, 2)              ' Non OK
dim as Vector2 vf = type(1, 2)           ' Common syntax
dim as Vector2 vg = Vector2(1, 2)        ' OK
dim as Vector2 vh = type<Vector2>(1, 2)  ' Common syntax

va = type(3, 4)                          ' Common syntax
vf = Vector2(3, 4)                       ' OK
vh = type<Vector2>(3, 4)                 ' Common syntax
TeeEmCee
Posts: 362
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: raylib vx.x headers built with type vs constructor

Post by TeeEmCee »

I created the raylib.bi that's distributed with FB; it's from fbbindings. There are a crazy number of alternative raylib bindings floating around, and my intention was to create a single standard one but I haven't succeeded because:
  • I haven't updated them since 3.5.0
  • people use various versions of raylib, but unfortunately each version is incompatible, requiring separate headers. So I was considering either shipping multiple versions of raylib.bi for the most recent raylib versions, or combining them all into a single .bi containing a bunch of #ifdefs (which fbfrog can do automatically).
  • Most of the alternative bindings contain customisations such as adding the constructor to Vector2, which makes it simpler to port raylib example code from C++ to FB. I wanted to add that constructor and others.
  • There are name clashes with the OpenGL headers so I should do some renaming
  • raygui requires manual porting and will be dependent on a certain raylib.bi
I would welcome any suggestions from raylib users or help to update or improve the bindings. I haven't touched it in a long time.

Porting raygui is heaps of work, how come you're doing that instead of using the existing port by Hesekiel? Updating to raylib 4?

As fxm excellently showed, adding the constructors changes the allowable syntax, so making that change to raylib.bi now is a compatibility breaking change because "dim as Vector2 ve = (1, 2)" is no longer allowed. (Maybe fbc should/could be changed to allow it?)
However I don't even know whether anyone has used my raylib.bi. (I wasn't even intending to include it with fbc yet, but Jeff copied it over from fbbindings.) So it may be OK to make this change.
fxm
Moderator
Posts: 11210
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: raylib vx.x headers built with type vs constructor

Post by fxm »

TeeEmCee wrote: Jun 21, 2022 10:37 ... adding the constructors changes the allowable syntax, so making that change to raylib.bi now is a compatibility breaking change because "dim as Vector2 ve = (1, 2)" is no longer allowed. (Maybe fbc should/could be changed to allow it?)
Currently, this exists for the one-parameter construction:
- using constructor with a single parameter
- using constructor with one parameter and the other parameters having defined default values.

This is called a "conversion-construction":
Dim As UDT u = (value)
Axle
Posts: 41
Joined: May 31, 2022 6:49
Location: Australia

Re: raylib vx.x headers built with type vs constructor

Post by Axle »

Hi @TeeEmCee and @fmx

The current rarlib.bi v4.0 had some issues. also the extra headers don't appear to be done and their is no corresponding raygui v3.x...
That mixed with the multiple versions and lack of documentation etc (No meaning to sound ungrateful to all the work previously done), I have decided to have a shot at updating it including documentation + setup and usage guides.

I need the latest versions as I will be using the latest for C and Python3 (Note raylib is C99 not C++). This is all part of a learner guide that I am writing with all examples to read with the same flow and logic (Rosetta Stone like) across C, FB and Python3, so I need to use the same versions else I will confuse students.

@fmx I am consuming your responses and will keep note of them when I have finished the conversions and begin testing raylib/gui.bi

I have to learn raylib and raygui on the fly so I will be learning raylib while I create the C and Python examples. This will give me the opportunity to bug test the FB version along side of the C and Py versions (Both currently the latest raylib/gui versions).

Why don't I jump in and spend a few years of my life learning to be proficient at FB?
I already use multiple languages side by side and if I had to pick a preference I would run with C/C++ over FB :) I only have so much time in my life to learn programming languages and am already familiar with over 50. Man can only consume so much knowledge lol
But I want to exemplify FB as a traditional foundation language (BASIC). Many modern main stream languages have been built from BASIC and C constructs (for example Python) and this builds the foundation for "Learning Programming" as opposed to "Learning a Language or coding"

It will take me a while to get through the ports using fbfrog and adding in the comments as well as the FB orientated documentation, but I will keep you all informed and take any advice/suggestions from anyone who has done the raylib binders previously with appreciation. It will end up gifted to the FB community when it's done :)

Axle
paul doe
Moderator
Posts: 1649
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: raylib vx.x headers built with type vs constructor

Post by paul doe »

Axle wrote: Jun 27, 2022 2:50 ...
But I want to exemplify FB as a traditional foundation language (BASIC). Many modern main stream languages have been built from BASIC and C constructs (for example Python) and this builds the foundation for "Learning Programming" as opposed to "Learning a Language or coding"
...
Exactly this. Many folk realize, after getting proficient with FB, that it effectively provides a pretty solid background to learn other, more complex languages (like C++); all it takes is practice, and to get out of the 'BASIC' mentality...

Regarding the lack of documentation, bear in mind that there is no other documentation available for Raylib other than their cheatsheet, and even less for some other modules (like raygui).
Mysoft
Posts: 829
Joined: Jul 28, 2005 13:56
Location: Brazil, Santa Catarina, Indaial (ouch!)
Contact:

Re: raylib vx.x headers built with type vs constructor

Post by Mysoft »

heh i lost count already on how many times i had to fix those stupid headers to get rid of that garbage crap... from a library that is C... and MUST NOT CONTAIN fellow OOP on it...
c-sanchez
Posts: 142
Joined: Dec 06, 2012 0:38

Re: raylib vx.x headers built with type vs constructor

Post by c-sanchez »

Hi Axle, you may find this post and all the comments interesting :)
viewtopic.php?t=31392
paul doe
Moderator
Posts: 1649
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: raylib vx.x headers built with type vs constructor

Post by paul doe »

Mysoft wrote: Jun 27, 2022 21:41 heh i lost count already on how many times i had to fix those stupid headers to get rid of that garbage crap... from a library that is C... and MUST NOT CONTAIN fellow OOP on it...
And who told you that constructors/destructors are OOP? As stated above, they're just a convenience. FreeBasic can't really do 'proper' OOP yet.
Mysoft
Posts: 829
Joined: Jul 28, 2005 13:56
Location: Brazil, Santa Catarina, Indaial (ouch!)
Contact:

Re: raylib vx.x headers built with type vs constructor

Post by Mysoft »

paul doe wrote: Jun 27, 2022 21:58
Mysoft wrote: Jun 27, 2022 21:41 heh i lost count already on how many times i had to fix those stupid headers to get rid of that garbage crap... from a library that is C... and MUST NOT CONTAIN fellow OOP on it...
And who told you that constructors/destructors are OOP? As stated above, they're just a convenience. FreeBasic can't really do 'proper' OOP yet.
if they are just "initialized" by a value... then its excusable, but unecessary... if they must "automagically" call a function when created... (meaning no function will be called if not using "new") then its OOP

string fors example are built-in so you have no control over the constructor function also... fbstrings does not require "new" you can allocate them with callocate or use anything as long they are zeroed... it will work just fine, so they are not OOP

so if it there was an "ifdef" to decide which version to use... then i would be fine... but forcing the constructor to be there... should not be done specially not for a C library lol...
c-sanchez
Posts: 142
Joined: Dec 06, 2012 0:38

Re: raylib vx.x headers built with type vs constructor

Post by c-sanchez »

Well paul doe I can only say that the only times I've managed to compile/run something simple with freebasic+raylib has been because mysoft has done me the favor of accommodating it, because that's the only way I've been able to do it.

This with Raylib 4.0 bindings for FreeBasic by WIITD
Image

Probably the same with the other available bindings, I haven't tried it in a while.
https://github.com/WIITD/raylib-freebasic
https://github.com/IchMagBier/raylib-fb
https://github.com/glasyalabolas/fb-raylib

Maybe there are -better- ways to write the code? I don't know.
I can only say that it's a pretty simple and nice code for someone starting out.
If you can show me how to do it -correctly- then fine.
fxm
Moderator
Posts: 11210
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: raylib vx.x headers built with type vs constructor

Post by fxm »

paul doe wrote: Jun 27, 2022 21:58 FreeBasic can't really do 'proper' OOP yet.
Maybe not quite (the Interfaces are missing), but most of the way is done thanks to UDTs with:
- Attributes and methods
- Encapsulation
- Abstraction
- Inheritance
- Polymorphism
and objects (dynamically) created as instances of such UDTs.
Axle
Posts: 41
Joined: May 31, 2022 6:49
Location: Australia

Re: raylib vx.x headers built with type vs constructor

Post by Axle »

To everyone that has replied...

Sorry, I was off line moving house for a couple of weeks.

OOP: From what I know and my experience with QBASIC4.5 was that it had basic object constructs. But we don't have to use OOP if we don't desire to.
Most OOP is built upon Imperative Procedural Orientation and OOP is more of a level up (I am not and engineer so forgive me if I have the terminology off by 1). FB Back end is C which is not natively OOP. It can be done in C with a lot of boilerplate coding, but that's why they created C++ :)

Most of what I do, even in Python 3 is from an "Imperative Procedural Orientation" but all orientations can blend a little in practice.

Thank you all for the reply's and suggestions :)

At present I have ( with some correspondence with ray and sorting out some hick ups) raylib V4.0.0 and raygui V3.1.x combined and compiling as a single dll for windows ( I am yet to do the Linux Shared Objects ). I can also add the current source version of physac but am leaving it to the side for now. Ray has told me that the headers in .\src\extras are dated and deprecated and will be removed from the raylib V4.2.0 release coming up soon. They (easings.h, rmem.h, gui_textbox_extended.h) will need to be updated if someone feels they have a need for them. Don't use the headers in "raylib\src\extras" as they are old versions, this includes .\extras\raygui.h. You will need to get raygui and physac current source (Not release version) and add it to the raylib source to compile all as a single dll. (There is a binary constant in raylib that I recommend changing to a HEX constant for C-99 compliance)

I have converted (Untested atm) raylib.h to raylib.bi including comments and some of the suggested fixes from my questions in the forum. I will do the other headers as time permits. I should end up with Raylib v4.0.0 and raygui V3.1 shared library dll/so as well as the header conversions rlibs.bi.

I have to double check with ray on the licensing for shipping the pre-compiled shared library but I think it will be OK.
I will compile the the shared library in winlibs GCC 9.3.0 (SJLJ exceptions) + MinGW-w64 7.0.0 (release 2) the same as FB if I run into backward compatibility issues with the current GCC version (I'm am uncertain how to roll back to and older GCC dev tools in Linux, so something I'll have to learn if needed.) I am also looking at creating the OpenGL3.3 version as well as the OpenGL_2.1 version as I get my students to use VirtualBox for much of the examples (VirtualBox can only do up to OpenGL v2.1).

I will look at the newer raylib V4.2 but it will depend heavily upon when the Python 3 bindings get done. <- I can't do all of it, Man has to sleep sometime lol.

Best regards
Axle
Axle
Posts: 41
Joined: May 31, 2022 6:49
Location: Australia

Re: raylib vx.x headers built with type vs constructor

Post by Axle »

paul doe wrote: Jun 27, 2022 3:25
Axle wrote: Jun 27, 2022 2:50 ...
But I want to exemplify FB as a traditional foundation language (BASIC). Many modern main stream languages have been built from BASIC and C constructs (for example Python) and this builds the foundation for "Learning Programming" as opposed to "Learning a Language or coding"
...
Exactly this. Many folk realize, after getting proficient with FB, that it effectively provides a pretty solid background to learn other, more complex languages (like C++); all it takes is practice, and to get out of the 'BASIC' mentality...

Regarding the lack of documentation, bear in mind that there is no other documentation available for Raylib other than their cheatsheet, and even less for some other modules (like raygui).
P.S. I don't know if you got a preview copy of the first books that I have done. I did post a copy for your self and the other FB Mods via Wormhole, but the link was only up for 24 hrs.

The books are formatted as an "Introduction to Programming" with a focus on programming as opposed to any language specific coding and an Imperative Procedural Orientation. All examples are done in C, FB and Python3 and can be read side by side in a "Rosetta Stone" fashion, keeping the emphasis on the programming flow and logic and highlighting the similarities between the 3 languages. It's actually a little eerie how close FB and Python3 are in syntax :) I can almost copy paste my FB code into Python3 and do some quick corrections and run the code.
All the examples will run/compile on Win as well as Linux.
If you didn't get a copy or wish to have a look, just let me know and I will organise a 24hr period to in a PM or something to put the link back up for you.

Book 2 covers the setting up of the 3 development environments for Windows and Linux with IDEs.

Best regards
Axle
Post Reply