OS X API Calls?

Miscellaneous Forums/MacOS X Discussion/OS X API Calls?

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.