Search code examples
javalualuaj

Calling a Lua function from LuaJ


So, I have a script that goes like so:

function testfunction()
    print("Test from testfunction");
end

I am able to call Java functions from Lua, but how do I accomplish the opposite? How do I call a Lua function from Java using LuaJ?


Solution

  • Taking a quick look at the LuaJ docs it seems to me that you have to get the org.luaj.vm2.LuaFunction object, representing the Lua function then apply the invoke method on it.