diff --git a/src/main.cpp b/src/main.cpp index d263c8a..7a396db 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -314,6 +314,9 @@ map loadedLibraries; // Map of function name to function pointer map externalFunctions; +// Libraries currently imported +vector libraries; + // Conversion functions GroundValue literalToGroundValue(const Literal& lit) { GroundValue gv; @@ -1898,6 +1901,17 @@ Literal exec(vector in, bool executingFunction) { error("First argument for use requires a string literal"); } + string libName = get(get(l.args[0]).val); + bool imported = false; + for (string lib : libraries) { + if (lib == libName) { + imported = true; + break; + } + } + + if (imported) break; + string groundLibsDir = getenv("GROUND_LIBS"); if (filesystem::exists(useName)) { @@ -1917,6 +1931,7 @@ Literal exec(vector in, bool executingFunction) { importing.push(get(get(l.args[0]).val)); Literal ret = exec(parser(lexer(in)), false); importing.pop(); + libraries.push_back(libName); } break; case Instructions::Extern: @@ -1936,6 +1951,16 @@ Literal exec(vector in, bool executingFunction) { error("First argument for extern requires a string literal"); } + bool imported = false; + for (string lib : libraries) { + if (lib == libName) { + imported = true; + break; + } + } + + if (imported) break; + // Add appropriate extension string fullLibName = libName; #ifdef _WIN32