doyle
New Member
Posts: 44
|
Post by doyle on Nov 19, 2010 0:59:30 GMT 1
Hi Peter,
Yeah, I know, I'm never satisfied... ;D
In HUG you do this when dealing with a C struct:
SUB hug_mouse_event (NUMBER widget, NUMBER data, long user)
LOCAL gdk, x, y
REM Works for GTK 2.x USEC typedef struct { int type; void *window; signed char send_event; unsigned int time; double x; double y; unsigned int state; int direction; } GdkEventScroll;
GdkEventScroll *mousescroll; mousescroll = (GdkEventScroll*)data;
Is there any way to be able to do something like this in native BaCon code?
LOCAL mousescroll TYPE GdkEventScroll* ... ... ... mousescroll = (GdkEventScroll*)data
BCX allows you to use the native struct name in your code. It sure would make using RECORDS easier in BaCon. You will still cast the data above but not have to repeat the struct code using USEC-END USEC
I know you would have to allow including the *.h files in your BaCon program or something similar. Just wondering what you think about this?
Maybe a new keyword such as below would automatically include the gtk.h file in the generated C code?
USING GTK
Thanks for a wonderful tool! mechanic
|
|
|
Post by Pjot on Nov 19, 2010 16:18:14 GMT 1
Hi Doyle, You already can add external .h files to your code. I never do that myself because I think its ugly. Anyway theoretically it works like this: However, there are so many dependencies between the GTK header files that you'll end up in specifying them all. Therefore, in case of GTK this maybe better: But it seems pointless to me to allow C syntax in a BASIC program. If you really need C structures, well, why not program C then...? The whole USEC/ENDUSEC already is a bad thing as it is... Best regards Peter
|
|
doyle
New Member
Posts: 44
|
Post by doyle on Nov 20, 2010 4:18:54 GMT 1
But it seems pointless to me to allow C syntax in a BASIC program. If you really need C structures, well, why not program C then...? The whole USEC/ENDUSEC already is a bad thing as it is... Because I don't like C! ;D How would you do the "GdkEventScroll" structure (in the hug_mouse_event SUB) in HUG in straight BaCon code? If you only use BaCon for straight basic code then normal RECORDS are fine as is. Using GTK brings in a mess of C code and structs. I suspect any gui library will. Is it possible to use native RECORDS, create a copy of the C struct (matching parameters and types) and make it work? How would one do a pointer to a struct member in BaCon? i.e. In C you would do: somestruct->somemember Just curious, thanks, Doyle
|
|
|
Post by Pjot on Nov 20, 2010 16:05:33 GMT 1
Well, me neither ;-) ...but BaCon is not a full C replacement, of course.
Well as long as you use these pointers within assignments or functions, then you can plainly use them within BaCon code. This is possible because BaCon is a lazy converter: it passes expressions and functions as-they-are to the C compiler. So when passing pointers or struct pointers these will be regarded as C code anyway.
Best regards Peter
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Nov 20, 2010 18:18:23 GMT 1
BaCon is a Basic to C translator or a preprocessor to a compiler. I think Peter did a great job with BaCon and it does what it's suppose to very well. I think Basic programmers using translators look at C as a black box and something that can be ignored. I'm interested in BaCon, BCX, QB64, ... Basic to C translators as I'm trying to be a better C programmer.
When I'm not in C learning mode and need to get something done quickly, I use ScriptBasic because anything I write is going to work and I don't have to worry if a translation to C will fly or not.
|
|