[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: LuaJava - How to pass Java objects to functions?
- From: "Danilo Tuler" <tuler@...>
- Date: Tue, 16 Dec 2003 18:44:20 -0300
> 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