Skip to content

Commit d77c894

Browse files
committed
Add SharedLibrary Support
1 parent d8d77a5 commit d77c894

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

MiniEngine.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,54 @@ namespace MiniEngine
13101310
va_end(ap);
13111311
}
13121312

1313+
SharedLibrary::SharedLibrary()
1314+
{
1315+
_obj=nullptr;
1316+
}
1317+
1318+
SharedLibrary::SharedLibrary(const std::string& Filename)
1319+
{
1320+
_obj=nullptr;
1321+
load(Filename);
1322+
}
1323+
1324+
SharedLibrary::~SharedLibrary()
1325+
{
1326+
if(_obj)
1327+
{
1328+
unload();
1329+
}
1330+
}
1331+
1332+
int SharedLibrary::load(const std::string& Filename)
1333+
{
1334+
if(_obj) return -1;
1335+
else
1336+
{
1337+
_obj=SDL_LoadObject(Filename.c_str());
1338+
if(_obj) return 0;
1339+
else return -2;
1340+
}
1341+
}
1342+
1343+
int SharedLibrary::unload()
1344+
{
1345+
if(_obj)
1346+
{
1347+
SDL_UnloadObject(_obj);
1348+
_obj=nullptr;
1349+
return 0;
1350+
}
1351+
else return -1;
1352+
}
1353+
1354+
void* SharedLibrary::get(const std::string& FunctionName)
1355+
{
1356+
if(!_obj) return nullptr;
1357+
else return SDL_LoadFunction(_obj,FunctionName.c_str());
1358+
}
1359+
1360+
13131361
int SDLSystem::SDLInit()
13141362
{
13151363
return SDL_Init(SDL_INIT_EVERYTHING);

MiniEngine.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,19 @@ namespace MiniEngine
429429
static void critical(const char* fmt,...);/// Critical
430430
};
431431

432+
class SharedLibrary
433+
{
434+
public:
435+
SharedLibrary();
436+
SharedLibrary(const std::string& Filename);
437+
~SharedLibrary();
438+
int load(const std::string& Filename);
439+
int unload();
440+
void* get(const std::string& FunctionName);
441+
private:
442+
void* _obj;
443+
};
444+
432445
class SDLSystem
433446
{
434447
public:

0 commit comments

Comments
 (0)