C Functions and Max

BlitzMax Forums/BlitzMax Programming/C Functions and Max

Steve Elliott(Posted 2005) [#1]
I want to call a C function, do some processing and then return the result to Max. But using the example in the docs the function is undefined according to the error code.

Where am I going wrong?

C Code:

int doubler (int x)
{
  return x+x;   
}

Max code:

Import "c_code.cpp"

Extern
  Function doubler (x)
End Extern

Print doubler(10)



Perturbatio(Posted 2005) [#2]
http://www.blitzbasic.com/Community/posts.php?topic=52256#583599


Steve Elliott(Posted 2005) [#3]
Thanks! Works fine now.


Steve Elliott(Posted 2005) [#4]
But that code doesn't seem to work with a C++ file (.cpp) - what's required for C++?

Also, if you use a pointer to an array in C++ how do you then return that pointer info into Max to access the array using MAX pointers?


Chris C(Posted 2005) [#5]
I'd have a look at the irrlicht mod that gman did
he wrapped all the C++ stuff in irrlict and it serves as
a good example of advanced intergration


Steve Elliott(Posted 2005) [#6]
Thanks Chris, I'll take a look - sounds a bit involved though.


Chris C(Posted 2005) [#7]
well thats c++ for you, you'd be FAR far better off doing
everthing you possibly can in max...

I try and keep all my data structures / variables defined by max, you can always pass values as parameters in functions

As for arrays you might want to consider a flat block of memory accessed as a bank.

Or better yet rewrite all the c++ code in max...