From d7c127f297d05afe14938bb2c586428c006a61a9 Mon Sep 17 00:00:00 2001 From: Nathanne Isip Date: Fri, 13 Dec 2024 17:50:11 +0800 Subject: [PATCH] Improved GLFW for installation and compilation with GLFW in standard library. --- .../VariableDeclarationExpression.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/n8/ast/expression/VariableDeclarationExpression.cpp b/src/n8/ast/expression/VariableDeclarationExpression.cpp index 8c68f00..531cbb4 100644 --- a/src/n8/ast/expression/VariableDeclarationExpression.cpp +++ b/src/n8/ast/expression/VariableDeclarationExpression.cpp @@ -22,6 +22,8 @@ #include #include +#include + #if defined(__unix__) || defined(__linux__) || defined(__APPLE__) # include #elif defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64) @@ -83,6 +85,34 @@ NativeFunction VariableDeclarationExpression::loadNativeFunction( ); #endif else { + std::filesystem::path path(library); + std::filesystem::path parentFolder = path.parent_path(); + + for(const auto& entry : std::filesystem::directory_iterator(parentFolder)) + if(entry.is_regular_file() && + #if defined(__APPLE__) + entry.path().extension() == ".dylib" + #elif defined(__unix__) || defined(__linux__) + entry.path().extension() == ".so" + #elif defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64) + entry.path().extension() == ".dll" + #endif + ) { + std::string entryDep = entry.path().filename().string(); + void* depHandle; + + #if defined(__APPLE__) + depHandle = dlopen(entryDep.c_str(), RTLD_LAZY); + #elif defined(__unix__) || defined(__linux__) + depHandle = dlopen(entryDep.c_str(), RTLD_LAZY); + #elif defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64) + depHandle = LoadLibraryA(entryDep.c_str()); + #endif + + if(Runtime::hasLoadedLibrary(entryDep)) + Runtime::addLoadedLibrary(entryDep, depHandle); + } + #if defined(__APPLE__) handle = dlopen(library.c_str(), RTLD_LAZY); #elif defined(__unix__) || defined(__linux__)