1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
11 * Dynamic Library loading.
16 #ifndef SQUIRRELJME_DYLIB_H
17 #define SQUIRRELJME_DYLIB_H
19 #include "sjme/stdTypes.h"
20 #include "sjme/error.h"
21 #include "sjme/debug.h"
25 #ifndef SJME_CXX_IS_EXTERNED
26 #define SJME_CXX_IS_EXTERNED
27 #define SJME_CXX_SQUIRRELJME_DYLIB_H
29 #endif /* #ifdef SJME_CXX_IS_EXTERNED */
30 #endif /* #ifdef __cplusplus */
32 /*--------------------------------------------------------------------------*/
34 #if defined(SJME_CONFIG_HAS_WINDOWS)
35 /** Symbol is exported through a library. */
36 #define SJME_DYLIB_EXPORT __declspec(dllexport)
37 #elif defined(SJME_CONFIG_HAS_GCC)
38 /** Symbol is exported through a library. */
39 #define SJME_DYLIB_EXPORT __attribute__((visibility("default")))
41 /** Symbol is exported through a library. */
42 #define SJME_DYLIB_EXPORT
45 #if defined(SJME_CONFIG_HAS_GCC)
46 /** Symbol is hidden in a library. */
47 #define SJME_DYLIB_HIDDEN __attribute__((visibility("hidden")))
49 /** Symbol is hidden in a library. */
50 #define SJME_DYLIB_HIDDEN
54 * Opaque dynamic library type.
58 typedef sjme_pointer sjme_dylib
;
61 * Closes the given dynamic library.
63 * @param inLib The library to close.
64 * @return Any error if it occurs.
67 sjme_errorCode
sjme_dylib_close(
68 sjme_attrInNotNull sjme_dylib inLib
);
71 * Looks up the given symbol in the library.
73 * @param inLib The library to look within.
74 * @param inSymbol The symbol to obtain from the library.
75 * @param outPtr The resultant pointer of the symbol.
76 * @return Any error if it occurs.
79 sjme_errorCode
sjme_dylib_lookup(
80 sjme_attrInNotNull sjme_dylib inLib
,
81 sjme_attrInNotNull sjme_lpcstr inSymbol
,
82 sjme_pointer
* outPtr
);
85 * Calculates the name of the given library for the current system.
87 * @param inLibName The input library name.
88 * @param outName The resultant library name.
89 * @param outLen The length of the output buffer.
90 * @return Any error code as applicable.
93 sjme_errorCode
sjme_dylib_name(
94 sjme_attrInNotNull sjme_lpcstr inLibName
,
95 sjme_attrOutNotNullBuf(outLen
) sjme_lpstr outName
,
96 sjme_attrInPositive sjme_jint outLen
);
99 * Opens a dynamic library.
101 * @param libPath The path to the library to open.
102 * @param outLib The resultant opened library.
103 * @return Any error if it occurs.
106 sjme_errorCode
sjme_dylib_open(
107 sjme_attrInNotNull sjme_lpcstr libPath
,
108 sjme_attrInOutNotNull sjme_dylib
* outLib
);
111 * Returns the current executable as a dynamic library.
113 * @param outLib The resultant library which points to ourself.
114 * @return Any resultant error, if any.
117 sjme_errorCode
sjme_dylib_self(
118 sjme_attrInOutNotNull sjme_dylib
* outLib
);
120 /** The debug handlers to use. */
121 extern SJME_DYLIB_EXPORT
122 sjme_debug_handlerFunctions
* sjme_debug_handlers
;
124 /*--------------------------------------------------------------------------*/
128 #ifdef SJME_CXX_SQUIRRELJME_DYLIB_H
130 #undef SJME_CXX_SQUIRRELJME_DYLIB_H
131 #undef SJME_CXX_IS_EXTERNED
132 #endif /* #ifdef SJME_CXX_SQUIRRELJME_DYLIB_H */
133 #endif /* #ifdef __cplusplus */
135 #endif /* SQUIRRELJME_DYLIB_H */