[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Thanks for the example, here is another question.
- From: "Danilo Tuler" <tuler@...>
- Date: Tue, 16 Dec 2003 14:21:06 -0300
> What I can't figure out is how to call a Lua function and get
> a return value from it?
In a way (very) similar you would do with the C API.
All the C API should be methods of the LuaState class.
Example:
////////////////////////////////////////////////
// LuaJavaTest.java
public class LuaJavaTest {
public static void main(String[] args) throws
ClassNotFoundException, LuaException {
LuaState l = LuaStateFactory.newLuaState();
// execute lua script
l.doFile("main.lua");
// put global lua function in the stack
l.getGlobal("test");
// pass parameters
l.pushString("foo");
// call the function
l.call(1, 1);
// print the result
System.out.println(l.toString(-1));
l.pop(1);
}
}
-------------------------------------------------
-- main.lua
function test (str)
return str .. str
end
-- Danilo