How can I embed Lua in Java?
Asked Answered
O

4

54

Is LuaJava a must for this? Or can I embed Lua into Java without it?

Organism answered 21/1, 2010 at 22:25 Comment(3)
I'm guessing that you'd prefer a pure-Java implementation of Lua (instead of LuaJava which uses native bits)? Or are you just looking for any alternative implementation?Before
A pure java implementation of LUA simply does not exist, and probably will never exist. It is a "C" project, and porting all that C to code java would be a huge undertaking, and I doubt the LUA authors see much benefit to that.Recondite
@Recondite actually most of the work is already done, about 10 years ago I ported the entire Lua 5.1.4 package to C# (and yes, it was a huge undertaking). A port from that to Java would, I imagine, be considerably easier.Anthrax
Y
30

LuaJ is easy to embed in Java. I did have to change a few lines of their source to get it to work how I expected (it didn't require the IO library automatically).

http://sourceforge.net/projects/luaj/

Yellowthroat answered 24/3, 2010 at 13:36 Comment(2)
I'm having a similar problem using Kahlua from IntelliJ. I am brand new to Lua and getting tripped up over an error, "attempted index of non-table" whenever I call "io.read()". I tried to require "io" but that doesn't work. Help?Numismatics
Does anyone compare the implementation of luaj and luajava?Fluorosis
S
12

Try also kahlua and Mochalua.

Selfinduced answered 21/1, 2010 at 22:58 Comment(1)
Kahlua now located on github, but not updated since 2013. Mochalua appears to have never been migrated off of Google Code, and is now archived; there are 4 versions on github, but none have been touched since 2015 and all just have the original 7 commits from the Google Code version from 2008-12-08.Tarantula
P
2

There is http://www.keplerproject.org/luajava/manual.html, but essentially lua is more suitable for integration with C. There are a bunch of other scripting languages with good java integration around though. Consider groovy, jruby or jython for starters.

Penley answered 21/1, 2010 at 22:46 Comment(2)
in this case I am stuck with lua otherwise I would go with jython being a python fan boyOrganism
To embed Jython is trivial, if that helps :PDeflected
C
2

Lua is a C library, you can embed it in Java but you'll have to interface the java virtual machine and Lua with some C code.

The LuaJava authors have already done that work - you're better off using that than writing your own.

Cohl answered 21/1, 2010 at 22:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.