Definition: |
atom a = call_back(integer rid)
-- or -- atom a = call_back({'+',integer rid}) |
Description: |
Get a machine address for the phix routine with the routine id rid.
The resulting address can be used by Windows, or an external C routine in a Windows .dll or Linux shared library (.so), as a "call-back" address for calling your phix routine. The second form, {'+',rid}, can/should be used on Windows if the routine will be called using the CDECL calling convention, instead of STDCALL. It has no effect when used on Linux, since that is always CDECL anyway. |
Comments: | You can set up as many call-back functions as you like.
When your routine is called, the argument values will all be machine-sized unsigned (positive) values. You should declare each parameter of your routine as atom, unless you want to impose tighter checking. Your routine must return a machine-sized integer value. Note that sign effects can come into play. The value -1 can, especially if it has been on a fairly colourful journey, arrive (on 32-bit) as #FFFFFFFF aka 4,294,967,295 and that will typecheck if you try and store it in an integer. Or it could occur the other way around completely, with some MAXUINT value in fact turning up as a -1. Code within the callback should be robust and, if at all possible, automatically map such (parameter) values. Theoretically call-backs are not thread safe, see Technicalia for details. |
Example Program: | demo\win32\window.exw, demo\linux\qsort.exu |
See Also: | routine_id, Calling C Functions, Icallback |
