Question

I'm attempting to make a game library in Java that uses Lua for the scripts. The real issue appears when I try to require a Java class (that is inside of a jar), and whenever I try to do so, I get an error much like the one below:

Exception in thread "main" org.luaj.vm2.LuaError: @/C:/xampp/htdocs/LevelDesigner/Projects/Lua Test/bin/levels/Test.lua:2 module
'resources.GameLevel' not found: resources.GameLevel
no field package.preload['resources.GameLevel']

How can I require a Java class that is within a jar? Right now it seems that, with Lua, I can only require .lua files, and not .class files. This is obviously problematic as Java files are compiled down to class files...And that is what I need to require.

Was it helpful?

Solution

The answer to this question is to use luajava.bindClass as opposed to require in all of your Lua scripts.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top