mirror of
https://github.com/Kiritow/MiniEngine.git
synced 2024-03-22 13:11:22 +08:00
Add SharedLibrary Support
This commit is contained in:
parent
d8d77a5bd2
commit
d77c894adc
|
@ -1310,6 +1310,54 @@ namespace MiniEngine
|
|||
va_end(ap);
|
||||
}
|
||||
|
||||
SharedLibrary::SharedLibrary()
|
||||
{
|
||||
_obj=nullptr;
|
||||
}
|
||||
|
||||
SharedLibrary::SharedLibrary(const std::string& Filename)
|
||||
{
|
||||
_obj=nullptr;
|
||||
load(Filename);
|
||||
}
|
||||
|
||||
SharedLibrary::~SharedLibrary()
|
||||
{
|
||||
if(_obj)
|
||||
{
|
||||
unload();
|
||||
}
|
||||
}
|
||||
|
||||
int SharedLibrary::load(const std::string& Filename)
|
||||
{
|
||||
if(_obj) return -1;
|
||||
else
|
||||
{
|
||||
_obj=SDL_LoadObject(Filename.c_str());
|
||||
if(_obj) return 0;
|
||||
else return -2;
|
||||
}
|
||||
}
|
||||
|
||||
int SharedLibrary::unload()
|
||||
{
|
||||
if(_obj)
|
||||
{
|
||||
SDL_UnloadObject(_obj);
|
||||
_obj=nullptr;
|
||||
return 0;
|
||||
}
|
||||
else return -1;
|
||||
}
|
||||
|
||||
void* SharedLibrary::get(const std::string& FunctionName)
|
||||
{
|
||||
if(!_obj) return nullptr;
|
||||
else return SDL_LoadFunction(_obj,FunctionName.c_str());
|
||||
}
|
||||
|
||||
|
||||
int SDLSystem::SDLInit()
|
||||
{
|
||||
return SDL_Init(SDL_INIT_EVERYTHING);
|
||||
|
|
13
MiniEngine.h
13
MiniEngine.h
|
@ -429,6 +429,19 @@ namespace MiniEngine
|
|||
static void critical(const char* fmt,...);/// Critical
|
||||
};
|
||||
|
||||
class SharedLibrary
|
||||
{
|
||||
public:
|
||||
SharedLibrary();
|
||||
SharedLibrary(const std::string& Filename);
|
||||
~SharedLibrary();
|
||||
int load(const std::string& Filename);
|
||||
int unload();
|
||||
void* get(const std::string& FunctionName);
|
||||
private:
|
||||
void* _obj;
|
||||
};
|
||||
|
||||
class SDLSystem
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue
Block a user