|
| 1 | +{ |
| 2 | + This file is part of: |
| 3 | +
|
| 4 | + SDL3 for Pascal |
| 5 | + (https://github.com/PascalGameDevelopment/SDL3-for-Pascal) |
| 6 | + SPDX-License-Identifier: Zlib |
| 7 | +} |
| 8 | + |
| 9 | +{* |
| 10 | + * # CategorySharedObject |
| 11 | + * |
| 12 | + * System-dependent library loading routines. |
| 13 | + * |
| 14 | + * Shared objects are code that is programmatically loadable at runtime. |
| 15 | + * Windows calls these "DLLs", Linux calls them "shared libraries", etc. |
| 16 | + * |
| 17 | + * To use them, build such a library, then call SDL_LoadObject() on it. Once |
| 18 | + * loaded, you can use SDL_LoadFunction() on that object to find the address |
| 19 | + * of its exported symbols. When done with the object, call SDL_UnloadObject() |
| 20 | + * to dispose of it. |
| 21 | + * |
| 22 | + * Some things to keep in mind: |
| 23 | + * |
| 24 | + * - These functions only work on C function names. Other languages may have |
| 25 | + * name mangling and intrinsic language support that varies from compiler to |
| 26 | + * compiler. |
| 27 | + * - Make sure you declare your function pointers with the same calling |
| 28 | + * convention as the actual library function. Your code will crash |
| 29 | + * mysteriously if you do not do this. |
| 30 | + * - Avoid namespace collisions. If you load a symbol from the library, it is |
| 31 | + * not defined whether or not it goes into the global symbol namespace for |
| 32 | + * the application. If it does and it conflicts with symbols in your code or |
| 33 | + * other shared libraries, you will not get the results you expect.:) |
| 34 | + * - Once a library is unloaded, all pointers into it obtained through |
| 35 | + * SDL_LoadFunction() become invalid, even if the library is later reloaded. |
| 36 | + * Don't unload a library if you plan to use these pointers in the future. |
| 37 | + * Notably: beware of giving one of these pointers to atexit(), since it may |
| 38 | + * call that Pointer after the library unloads. |
| 39 | + } |
| 40 | + |
| 41 | +{* |
| 42 | + * An opaque datatype that represents a loaded shared object. |
| 43 | + * |
| 44 | + * \since This datatype is available since SDL 3.2.0. |
| 45 | + * |
| 46 | + * \sa SDL_LoadObject |
| 47 | + * \sa SDL_LoadFunction |
| 48 | + * \sa SDL_UnloadObject |
| 49 | + } |
| 50 | +type |
| 51 | + PPSDL_SharedObject = ^PSDL_SharedObject; |
| 52 | + PSDL_SharedObject = type Pointer; |
| 53 | + |
| 54 | +{* |
| 55 | + * Dynamically load a shared object. |
| 56 | + * |
| 57 | + * \param sofile a system-dependent name of the object file. |
| 58 | + * \returns an opaque Pointer to the object handle or nil on failure; call |
| 59 | + * SDL_GetError() for more information. |
| 60 | + * |
| 61 | + * \threadsafety It is safe to call this function from any thread. |
| 62 | + * |
| 63 | + * \since This function is available since SDL 3.2.0. |
| 64 | + * |
| 65 | + * \sa SDL_LoadFunction |
| 66 | + * \sa SDL_UnloadObject |
| 67 | + } |
| 68 | +function SDL_LoadObject(sofile: PAnsiChar): PSDL_SharedObject; cdecl; |
| 69 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_LoadObject' {$ENDIF} {$ENDIF}; |
| 70 | + |
| 71 | +{* |
| 72 | + * Look up the address of the named function in a shared object. |
| 73 | + * |
| 74 | + * This function Pointer is no longer valid after calling SDL_UnloadObject(). |
| 75 | + * |
| 76 | + * This function can only look up C function names. Other languages may have |
| 77 | + * name mangling and intrinsic language support that varies from compiler to |
| 78 | + * compiler. |
| 79 | + * |
| 80 | + * Make sure you declare your function pointers with the same calling |
| 81 | + * convention as the actual library function. Your code will crash |
| 82 | + * mysteriously if you do not do this. |
| 83 | + * |
| 84 | + * If the requested function doesn't exist, nil is returned. |
| 85 | + * |
| 86 | + * \param handle a valid shared object handle returned by SDL_LoadObject(). |
| 87 | + * \param name the name of the function to look up. |
| 88 | + * \returns a Pointer to the function or nil on failure; call SDL_GetError() |
| 89 | + * for more information. |
| 90 | + * |
| 91 | + * \threadsafety It is safe to call this function from any thread. |
| 92 | + * |
| 93 | + * \since This function is available since SDL 3.2.0. |
| 94 | + * |
| 95 | + * \sa SDL_LoadObject |
| 96 | + } |
| 97 | +function SDL_LoadFunction(handle: PSDL_SharedObject; name: PAnsiChar): TSDL_FunctionPointer; cdecl; |
| 98 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_LoadFunction' {$ENDIF} {$ENDIF}; |
| 99 | + |
| 100 | +{* |
| 101 | + * Unload a shared object from memory. |
| 102 | + * |
| 103 | + * Note that any pointers from this object looked up through |
| 104 | + * SDL_LoadFunction() will no longer be valid. |
| 105 | + * |
| 106 | + * \param handle a valid shared object handle returned by SDL_LoadObject(). |
| 107 | + * |
| 108 | + * \threadsafety It is safe to call this function from any thread. |
| 109 | + * |
| 110 | + * \since This function is available since SDL 3.2.0. |
| 111 | + * |
| 112 | + * \sa SDL_LoadObject |
| 113 | + } |
| 114 | +procedure SDL_UnloadObject(handle: PSDL_SharedObject); cdecl; |
| 115 | + external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_UnloadObject' {$ENDIF} {$ENDIF}; |
| 116 | + |
0 commit comments