OS X API Calls?
Miscellaneous Forums/MacOS X Discussion/OS X API Calls?
Is BlitzMax capable of interfacing with the OS X API system?
Thanks,
-Garrett
I think yes but i don't know how.......i'm sorry.........
Check the help section "Language/Advanced topics". Yes, you can access system APIs. ;-)
Heyyyyy..... Totally forgot I asked this question. Thanks Lestroso, and thanks
Winni for the replies.
Winni, thanks, I'll check the docs on that.
-Garrett
winni ....in that page there's only a c++ and asm discussion..........so you can implement c++and asm in your program.....but i dont' see the api calls.....
bye
--Lestroso
Hi Lestroso,
But that is exactly what this whole API thing is about: You use this feature of BlitzMax to write wrappers for API calls.
Usually, you write some C-code to call the system function that you need and just link it to your Blitzmax program. In the C module, the most important part will probably be to include the required header files and call the correct system functions.
The point here is that you will have to study quite a lot of Apple's developer documentation to find what you need.
This little thing here e.g. calls an OS X API function that will spawn a new thread running a function that you wrote in BlitzMax:
Import "-std=c99" '
Import "macthread.c" '
Extern
Function CreateThread(threadfunction())="bmx_createthread"
EndExtern
Now define a function in your BlitzMax code and call CreateThread( myFunction ).
The C-code does the actual API calls. In this case, it will call the system functions to create a new thread.
macthread.c:
----------------
#include <stdlib.h>
#include <pthread.h>
long bmx_createthread(void *functionC())
{
int rc1;
pthread_t thread1;
pthread_attr_t stack_size;
pthread_attr_init(&stack_size);
pthread_attr_setstacksize(&stack_size, 1048576);
rc1=pthread_create(&thread1,&stack_size,functionC,NULL);
return (long)thread1;
}
If you look around for SQLiter and TeaMonkey's SQLite module, then you can get an impression of how it (sometimes) can be done without writing C-code yourself. But still, you need to know what to link against your own code, and without some basic understanding of C (not C++, just C) you will most likely not get very far.
BTW, the whole MaxGUI thing is basically a huge wrapper for API calls - actually Cocoa calls (which is an Objective-C API).
Hope this helps a bit,
W.
Nice reply Wini !
what is the ="bmx_createthread" text after the external function declaration?
Winny i'm sorry, you're right....nice example....do you have something else examples codes ?
thanks a lot...........
Lestroso
Hi there,
Lestroso, you can download GMan's MySQL & PostgreSQL wrapper classes, he's using that stuff a lot. Or you can scrutinize the MaxGUI source code.
AngelDaniel, I guess =bmx_createthread maps the BlitzMax function declaration to the C-function. I only took that code from the german BlitzMax forum and modified it a bit so it would run on my Mac, but I think this is what the = thing actually means.
HTH,
W.
So you have to provide some kind of internal symbol name, and you can make it up, doesn't have to be predefined format?
My question:
Does anyone see how it may be possible to use the screensaver/screensaver.h framework (and any of the headers that it includes) WITHIN BlitzMax, to use BlitzMax as the compiler, to get it to produce a real Mac screensaver? Aside for all the extra files and folders that a screensaver bundle needs, is it feasible that Blitz could compile the appropriate file with the appropriate code to make it be recognized as a valid screensaver?
what is the ="bmx_createthread" text after the external function declaration?
It's not required if you use the same function name in Max as you defined in C. e.g
Extern
Function bmx_CreateThread(threadfunction())
End Extern