55

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

Aki
  • 2,818
  • 1
  • 15
  • 23
  • 4
    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? – ZoogieZork Jan 21 '10 at 22:47
  • 1
    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. – deltamind106 Aug 15 '18 at 20:43
  • @deltamind106 actually most of the work is already done, about 10 years ago I [ported the entire Lua 5.1.4 package to C#](https://github.com/Myndale/KopiLua) (and yes, it was a huge undertaking). A port from that to Java would, I imagine, be considerably easier. – Mark Feldman Sep 16 '20 at 11:40

4 Answers4

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/

Ben Ziegler
  • 431
  • 4
  • 3
  • 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? – Cliff Feb 03 '12 at 16:23
  • Does anyone compare the implementation of luaj and luajava? – swcai Mar 27 '12 at 04:14
12

Try also kahlua and Mochalua.

lhf
  • 70,581
  • 9
  • 108
  • 149
  • Kahlua now located [on github](https://github.com/krka/kahlua2), 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. – Pixelstix Nov 16 '20 at 23:55
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.

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
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.

nos
  • 223,662
  • 58
  • 417
  • 506