GLBasic forum

Main forum => Bug Reports => Topic started by: Moebius on 2011-Feb-05

Title: IDE doesn't recognise 'IMPORT'ed functions with more than one word for a type
Post by: Moebius on 2011-Feb-05
Making use of Trucidare's awesome iBluetooth wrapper, I noticed that in the IDE, the following line:
Code (glbasic) Select
IMPORT "C" const char* GLB_iBT_Recv()
'Creates' a new function in the IDE called "char*" rather than GLB_iBT_Recv().
Similarly this is recognised as importing 'int':
Code (glbasic) Select
IMPORT "C" long int hello()

There doesn't seem to be any problems when compiling, but somewhere in its code the IDE needs to recognise that the last 'word' is the function rather than the next word after the first type-specifying keyword.
Title: Re: IDE doesn't recognise 'IMPORT'ed functions with more than one word for a type
Post by: Kitty Hello on 2011-Feb-07
Uhm.. I didn't understand that fully now :/
Title: Re: IDE doesn't recognise 'IMPORT'ed functions with more than one word for a type
Post by: Moebius on 2011-Feb-07
Sorry  :whistle:

If I type in the IDE something like:
Code (glbasic) Select
IMPORT "C" int MyFunction()
... then 'MyFunction()' is recognised in the IDE, put in the 'Jumps' list, highlighted, etc.

However, if the type is more than one word long e.g.:
Code (glbasic) Select
IMPORT "C" const char* MyString()
IMPORT "C" long int MyInt()


Then instead of recognising "MyString()" and "MyInt()", the IDE recognises "char*" and "int" as functions!

The implications of this aren't that drastic, but it shouldn't be too hard to fix?
ATM the IDE recognises the word after the first type defining one as the function whereas it needs to look for the last word in the line before the '()'.

Hopefully I'm more understandable now.  Please let me know if I'm not  :S
Title: Re: IDE doesn't recognise 'IMPORT'ed functions with more than one word for a type
Post by: Kitty Hello on 2011-Feb-07
when you return char*, only?
I mean, the const is ignored anyway.
Title: Re: IDE doesn't recognise 'IMPORT'ed functions with more than one word for a type
Post by: Moebius on 2011-Feb-08
I mean in the IDE, if you look in the jumps list "char*" is listed as a function!  And not "MyString()"   :(  Try entering the example IMPORTs I gave and you'll see what I mean...
Sry for the confusion.
Title: Re: IDE doesn't recognise 'IMPORT'ed functions with more than one word for a type
Post by: Kitty Hello on 2011-Feb-08
Doh! I got it. I'll fix that.

But please write:
Code (glbasic) Select

IMPORT "C" char* MyString2()

and everything is fine.
Title: Re: IDE doesn't recognise 'IMPORT'ed functions with more than one word for a type
Post by: Moebius on 2011-Feb-08
Oh doesn't const mean anything then anyway?  My skills in C++ are somewhat lacking  :whistle:
Anyway, thanks.  :good:
Title: Re: IDE doesn't recognise 'IMPORT'ed functions with more than one word for a type
Post by: Kitty Hello on 2011-Feb-08
const char* means, you cannot change the contents the pointer points to. GLBasic, however, using IMPORT will convert your char*/const char* to a DGStr string, thus making a copy of your data anyway. It's safe.

What you have to be aware of is, that returning a char* requires a valid memory buffer that is still alive after the function returns.