blazingkin
blazingkin

Reputation: 572

Creating a lua interface in java

Is there a way that I can make my program in java, but make all of the plugins lua based? How can I do all of the hooks and such across the languages and can I access the functions and such from Java? I would prefer if this were to be done during runtime as opposed to having a cross-compiler that changes it beforehand.

Upvotes: 3

Views: 1411

Answers (2)

Michal Kottman
Michal Kottman

Reputation: 16753

One alternative is LuaJava. It allows you to use Lua scripting in Java program. Speaking literally about implementing interfaces in Lua:

LuaJava also allows Java to implement an interface using Lua. This way any interface can be implemented in Lua and passed as parameter to any method, and when called, the equivalent function will be called in Lua, and it's result passed back to Java.

An example of such implementation:

button_cb = {}
function button_cb.actionPerformed(ev) ... end
buttonProxy = luajava.createProxy("java.awt.ActionListener",  button_cb)

Of course, you can also call "normal" Lua functions from Java, using the familiar C API (adapted to Java).

Upvotes: 1

kartben
kartben

Reputation: 2535

In Lua Development Tools we are doing the parsing of the Lua source code using Metalua, and this is made possible by JNLua. Not only can you call Lua code from Java, but the Lua code can also manipulate/instantiate Java classes!

Upvotes: 1

Related Questions