Skip to content

Commit

Permalink
Auto-file extension concaternation on native library loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Oct 10, 2024
1 parent da6ba35 commit 9ffca68
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/ast/statement/VariableDeclarationStatement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,37 @@ NativeFunction VariableDeclarationStatement::loadNativeFunction(
std::unique_ptr<Token> address
) {
void* handle;
if(Runtime::hasLoadedLibrary(libName))
std::string library = std::string(libName.c_str());

if(Runtime::hasLoadedLibrary(libName)) {
#if defined(__unix__) || defined(__linux__)

library += ".so";
handle = Runtime::getLoadedLibrary(libName);

#elif defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)

library += ".dll";
handle = static_cast<HMODULE>(
Runtime::getLoadedLibrary(libName)
);

#endif
}
else {
#if defined(__unix__) || defined(__linux__)
handle = dlopen(libName.c_str(), RTLD_LAZY);

library += ".so";
handle = dlopen(library.c_str(), RTLD_LAZY);

#elif defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
handle = LoadLibraryA(libName.c_str());

library += ".dll";
handle = LoadLibraryA(library.c_str());

#endif

Runtime::addLoadedLibrary(libName, handle);
Runtime::addLoadedLibrary(library, handle);
}

if(!handle) {
Expand Down

0 comments on commit 9ffca68

Please sign in to comment.