HI I like to know if directly in Glbasic, can pass a different number of arguments in a same function.
I look a C++ tutorial on explain this, and only it´s for know it... this can be do directly from Glbasic?¿, or is INLINE command needed.
Thanks,
Iván J.
What do you mean with a different number of arguments?
Do you mean real overloading of functions?
function a: a%, b%
endfunction
function a: a%
endfunction
If yes, no it's not possible in GLBasic.
If you mean different arguments in one function, it's possible!
function a: a%=10, b$="Hello", c#=1.0
endfunction
a(5)
a(5, "blah")
a(5, "bla", 3.2)
cheers
variable arguments are not supported. It's a feature that's not really type safe and very dangerous to use. Example:
printf("%d %d", 6) // beeeeeep - no 2nd argument given, no compiler error, runtime crash/strange behaviour.
Ok, thanks for all the replies, Masters.
You could also set default values for FUNCTION variables and sort of emulate it that way.
Thanks MrTatoad
How hard would function overloading be to implement?
Doesn't C++ support this natively?
So many times I wanted to have the same function name accept different data types!
The obvious work around is to name them differently, but then you have to remember those 'non-obvious' names.
Or, could GLBasic add a suffix to each function name behind the scenes when compiling that states the data types accepted?
FUNCTION Add: a%, b%
would compile to
FUNCTION Add_ii: a%, b%
FUNCTION Add: a#, b#
would compile to
FUNCTION Add_ff: a%, b%
Then of course you would need to identify at compile time what function to use for each call.
I know I'm just dreaming, but thought I'd throw it out there!
then you get stupid compiler warnings for ambiguous calls.
Do other BASICs allow this?
Well, VB.Net ! =D
I just find it is a great feature that would work well with TYPE libraries.
I know this isn't really requested by many people, so I can live without it.
Good idea - and you automatically know how many parameters to deal with.
I'd like more than overloading, the posibility to use parameters in SUBs, like in the funtions. Will be very useful and is supported in many BASIC flavours. For example:
SUB DrawHero: %x, %y, %life, name$
....
ENDSUB
why not use a function instead?
Quote from: Kitty Hello on 2011-Oct-05
then you get stupid compiler warnings for ambiguous calls.
Do other BASICs allow this?
Hm, Monkey does allow overloaded functions, but it's OOP so you can't really compare it with GLBasic.
I would like Function overloading, too!
But then GLBasic goes more and more OOP! :D I think Gernot doesn't want "OOP" in GLBasic.^^
cheers
QuoteI think Gernot doesn't want "OOP" in GLBasic.
Ha, ya, that's what I read a while ago too!
But most OOP features would be completely optional to use, you don't NEED to overload your functions, but it could be there for those that want it. Not sure how difficult it is for Gernot to program that however!
It would be cool also to have an option of GL'Basic' that skips the 'basic' part and lets us develop purely in C++! 8)
Have all the same graphics and input functions still available, but lets us use C++ syntax. The compiling stage would seem simple! (and yes, I know there's INLINE available but it's not the same!)
What, I'm kicked out of this forum?! ha :D
where is the difference of inline and pure C++? I don't get it.
INLINE
DGStr str = "Hello World";
PRINT( str, 100, 100);
SHOWSCREEN();
MOUSEWAIT();
ENDINLINE
So all of GLBasic functions are available using INLINE?
I could code the entire game with multiple functions and classes in C++, as long as I wrap the file with INLINE..ENDINLINE?
Would this work with multiple project files too where you could call functions from another file?
At the very least I could code some libraries in C++, which is something I have considered.
QuoteSo all of GLBasic functions are available using INLINE?
I could code the entire game with multiple functions and classes in C++, as long as I wrap the file with INLINE..ENDINLINE?
Yes and Yes!
Mainly to use GLBasic's commands without having to recode that functionality.
I'm not about to write my own OpenGL library! :S
But realistically I'm fine with writing in basic, I can live with the few limitations.
Plus, I don't want to rewrite any of my code, although that would let me procrastinate a little longer =D
Quote from: Ocean on 2011-Oct-07
Quote from: MrTAToad on 2011-Oct-07
QuoteSo all of GLBasic functions are available using INLINE?
I could code the entire game with multiple functions and classes in C++, as long as I wrap the file with INLINE..ENDINLINE?
Yes and Yes!
And that could invoke the question: why use GLB at all if you're going to do it that way? What would be the point?
Multi-platform support would be a lot harder if you just used C, although, of course, if you didn't want multi-platform support, then you would use some C system.