Move platform-specific dynamic lib default file extension out of Game.c and into Platform.c where it belongs

This commit is contained in:
UnknownShadow200 2019-09-28 07:05:24 +10:00
parent 7cfd8a8570
commit be20b6d093
3 changed files with 14 additions and 11 deletions

View File

@ -373,14 +373,6 @@ static void Game_LoadOptions(void) {
static void Game_LoadPlugins(void) { }
#else
static void Game_LoadPlugin(const String* path, void* obj) {
#if defined CC_BUILD_WIN
static const String ext = String_FromConst(".dll");
#elif defined CC_BUILD_OSX
static const String ext = String_FromConst(".dylib");
#else
static const String ext = String_FromConst(".so");
#endif
void* lib;
void* verSymbol; /* EXPORT int Plugin_ApiVersion = GAME_API_VER; */
void* compSymbol; /* EXPORT struct IGameComponent Plugin_Component = { (whatever) } */
@ -388,7 +380,7 @@ static void Game_LoadPlugin(const String* path, void* obj) {
ReturnCode res;
/* ignore accepted.txt, deskop.ini, .pdb files, etc */
if (!String_CaselessEnds(path, &ext)) return;
if (!String_CaselessEnds(path, &DynamicLib_Ext)) return;
res = DynamicLib_Load(path, &lib);
if (res) { Logger_DynamicLibWarn2(res, "loading plugin", path); return; }

View File

@ -1339,6 +1339,8 @@ ReturnCode Updater_GetBuildTime(TimeMS* ms) {
*-------------------------------------------------------Dynamic lib-------------------------------------------------------*
*#########################################################################################################################*/
#if defined CC_BUILD_WIN
const String DynamicLib_Ext = String_FromConst(".dll");
ReturnCode DynamicLib_Load(const String* path, void** lib) {
TCHAR str[NATIVE_STR_LEN];
Platform_ConvertString(str, path);
@ -1355,10 +1357,17 @@ bool DynamicLib_DescribeError(ReturnCode res, String* dst) {
return Platform_DescribeError(res, dst);
}
#elif defined CC_BUILD_WEB
ReturnCode DynamicLib_Load(const String* path, void** lib) { return ERR_NOT_SUPPORTED; }
ReturnCode DynamicLib_Load(const String* path, void** lib) { return ERR_NOT_SUPPORTED; }
ReturnCode DynamicLib_Get(void* lib, const char* name, void** symbol) { return ERR_NOT_SUPPORTED; }
bool DynamicLib_DescribeError(ReturnCode res, String* dst) { return false; }
bool DynamicLib_DescribeError(ReturnCode res, String* dst) { return false; }
#elif defined CC_BUILD_POSIX
/* TODO: Should we use .bundle instead of .dylib? */
#ifdef CC_BUILD_OSX
const String DynamicLib_Ext = String_FromConst(".dylib");
#else
const String DynamicLib_Ext = String_FromConst(".so");
#endif
ReturnCode DynamicLib_Load(const String* path, void** lib) {
char str[NATIVE_STR_LEN];
Platform_ConvertString(str, path);

View File

@ -73,6 +73,8 @@ CC_API ReturnCode Updater_Start(void);
/* Returns the last time the application was modified, as number of milliseconds since 1/1/0001 */
CC_API ReturnCode Updater_GetBuildTime(TimeMS* ms);
/* The default file extension used for dynamic libraries on this platform. */
extern const String DynamicLib_Ext;
/* Attempts to load a native dynamic library from the given path. */
CC_API ReturnCode DynamicLib_Load(const String* path, void** lib);
/* Attempts to get the address of the symbol in the given dynamic library. */