lua-users home
lua-l archive

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


<quote who="Danilo Tuler">
>
>> 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
>
>
>

Cool! That is simpler than I thought it would be, but I still can't
figureout how to pass something into a Lua implemented Interface like your
first example that contained the following code.
		LuaState l = LuaStateFactory.newLuaState();
		l.doFile("LuaLogic.lua");
		LuaObject logic = l.getLuaObject(-1);
		IBusinessLogic jlogic = (IBusinessLogic)
logic.createProxy("IBusinessLogic");
		jlogic.doLogic();
		l.pop(1);

if the interface signatgure was
     TestDataObject IBusinessLogic.doLogic( TestDataObject );

what would I have to do to the above code to pass the TestDataObject in
and get one back?

Thanks for all the help.


-- 
Jarrod H. Roberson