0

Im trying to load the json module in Java code. The example in the Doc shows that it should go like this but it doesnt work. Does it require the module to be in the project or it loads it from LUA_PATH. does anyone have any experience with this issue?

Globals globals = JsePlatform.standardGlobals();
globals.get("require").call( LuaValue.valueOf("json") );

Exception in thread "main" org.luaj.vm2.LuaError: module 'json' not found: json no field package.preload['json'] json.lua no class 'json'

It looks like it is trying just within the LuaJ package.

alknows
  • 1,972
  • 3
  • 22
  • 26

1 Answers1

0

If the json module you are using is written in lua, then it'll need to be in the package.path like any other lua module.

If it's written in java then LuaJ will need to be able to find json.class in the normal Java classpath.

Alex
  • 1,017
  • 5
  • 11
  • Im developing in Eclipse, which would be the absolute path to "package.path"? Its already in LUA_PATH/lua. That would be for me "C:\Program Files (x86)\Lua\5.1\lua". – alknows Jan 27 '14 at 15:38
  • 1
    Just run a lua script that says `print(package.path)`. – Alex Jan 27 '14 at 16:13
  • I'll take a punt in this but put json.lua in the top level directory of your Eclipse project and see if that works. – Alex Jan 27 '14 at 16:24
  • Adding the lua_path to package.path had it moving forward. But the Json library is written in lua and it requires a lpeg.dll module which normally should be imported from lua. – alknows Jan 27 '14 at 19:34
  • Can't use use a pure Lua json module? Then it should work ok. The does appear to be an lpeg project with Luaj bindings, just Google luaj lpeg, but whether it works or not may depend on which version of luaj you're using. – Alex Jan 28 '14 at 15:57
  • jnlua supports loading dll and so library files: https://code.google.com/archive/p/jnlua/ – Scott Wardlaw Feb 23 '16 at 18:31