lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


 
> How to pass Java objects to functions?

It's simpler than you think.
Just pass the object using LuaState.pushJavaObject and use it in Lua with
the : operator

// java code
LuaState l = LuaStateFactory.newLuaState();
l.doFile("main.lua");
TestDataObject obj = new TestDataObject("test", 1, true);
System.out.println("before lua: " + obj.toString());
l.getGlobal("test");
l.pushJavaObject(obj);
l.call(1, 0);
System.out.println("after lua: " + obj.toString());


-- main.lua
function test (obj)
	obj:setString("lua")
	obj:setInt(2)
	obj:setBoolean(false)
end