gudzpoz / luajava

Lua for Java on Windows, Mac OS X, Linux, Android. 5.1, 5.2, 5.3, 5.4, LuaJ or LuaJIT.
https://gudzpoz.github.io/luajava/
Other
154 stars 21 forks source link

External loaders are removed after another `openLibrary("package")` #35

Closed gudzpoz closed 2 years ago

gudzpoz commented 2 years ago

When calling setExternalLoader, we append to the global package.loaders / package.searchers only once by using an AtomicReference. However, openLibrary("package") or openLibraries() reset the loaders / searchers. Our modifications will then be gone and never get restored.

L.openLibrary("package");
L.setExternalLoader(new ClassPathLoader());
L.run("require('file.on.the.classpath')");  // OK
L.openLibrary("package");
L.run("require('file.on.the.classpath')");  // Fails
L.setExternalLoader(new ClassPathLoader());
L.run("require('file.on.the.classpath')");  // Fails
gudzpoz commented 2 years ago

Fixed by https://github.com/gudzpoz/luajava/commit/d28856aad8ddb89c4c67b3d1298cab4a840ba7a6