import C functions

Previous topic - Next topic

Kitty Hello

GLBasic can now include native C functions and files w/o INLINE:

Main.gbas file
Code (glbasic) Select


REQUIRE "test1.cpp" // advise the compiler to take a cpp file, too

IMPORT "C" int Muh(); // IMPORT is like "extern" in C++. All the rest is the same.

Muh() // call it


test1.cpp
Code (glbasic) Select

#include "glb.h"

extern "C" int Muh()
{
STDOUT("Muh!");
}


Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

bigsofty

#2
Excellent Gernot, thank you, could we have a mini tutorial please specifying...


  • What variable types can be used within GLBasic
  • How pointers are dealt with?
  • Is it possible to pass C structures, if so, how is this used within GLBasic?
  • Anything else regarding passing data back and forth ;)

Overall a big  :good: from me!
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Quentin

really good news! top!

@bigsofty
let's try it out :) I hope it's possible to use class definitions within the cpp files

MrTAToad

It'll make things easier

Kitty Hello

no structure passing. Make that inline or a wrapper. type conversion is:

int, long, short, char, void* -> DGNat
double, float -> DGInt
int& -> DGNat BYREF
double& -> DGInt BYREF
char*, const char* -> DGStr

Quentin

is this feature ready for download in Beta Release?

Hatonastick

Ooooh I like INLINE though!

I like this idea a lot too though. :)  Definitely a cool feature.

Hatonastick

Quote from: Ocean on 2009-Aug-05
Quote from: Hatonastick on 2009-Aug-05
Ooooh I like INLINE though!

it's not mutually exclusive, so....  :)
Darn, so there's no point ranting, raving and demanding it be put back the way it was then?  =D

Schranz0r

That IMPORT-Functions need to highlight on the IDE...( and Autocompletion/ see the parameters on the "tooltip" at the bottom of the IDE)

Gernot, realy good work!
I can create my "Menu wrapper" from windows.h with that. (without a DLL and YES i can include <windows.h>... but <iostream> crashs) :)
Works fine  :good:
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Hemlos

The line, which IMPORT is written on, is highlighted blue, with the new black theme.

But the declaration itself(IMPORT), and the declared command words are not highlighted.

Question: This new command import, is it the same thing as setting up an inline?
Bing ChatGpt is pretty smart :O

MrTAToad

Import allows access to the function included by Require - its somewhat like Declare.

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

bigsofty

Quote from: Kitty Hello on 2009-Aug-05
no structure passing. Make that inline or a wrapper. type conversion is:

int, long, short, char, void* -> DGNat
double, float -> DGInt
int& -> DGNat BYREF
double& -> DGInt BYREF
char*, const char* -> DGStr


Whoops missed this reply, thanks Gernot!  =D
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)