gmod-lcpu/native/projects/lucore/src/Library.cpp

37 lines
793 B
C++
Raw Normal View History

#include <format>
#include <lucore/Library.hpp>
#include <string>
#include "OsLibrary.hpp"
namespace lucore {
namespace {
std::string FormatLibraryName(std::string_view dllName) {
#ifdef _WIN32
return std::format("{}.dll", dllName);
#else
2023-07-18 06:01:32 -04:00
return std::format("lib{}.so", dllName);
#endif
}
} // namespace
Library* Library::Open(std::string_view dllname) {
2023-07-18 06:01:32 -04:00
return new Library(detail::OsOpenLibrary(FormatLibraryName(dllname).c_str()));
}
bool Library::Loaded(std::string_view dllname) {
return detail::OsLibraryLoaded(FormatLibraryName(dllname).c_str());
}
Library::~Library() {
if(handle) {
2023-07-18 06:01:32 -04:00
detail::OsFreeLibrary(handle);
}
}
void* Library::SymbolImpl(const char* symbolName) {
2023-07-18 06:01:32 -04:00
return detail::OsLibrarySymbol(handle, symbolName);
}
} // namespace lucore