Lua learning Note 3 android calls Lua. The Lua script calls back Java using LoadLib and transmits multiple parameters.
Multiple parameters can be received in Java and each parameter is displayed.
The method for loading the Lua script in android is not the focus of this article. You can refer to the notes in front of this blog.
Lua script:
[Plain]
Function callback ()
Luajava. loadLib ("cn. hpc. common. lua. LoadLibExample", "open") -- call the open method of the LoadLibExample class in the cn. hpc. common. lua package.
JavaObjcet. methodOpen ("1", 4) -- two parameters are returned.
JavaObjcet. methodOpen ("2", "blog", "http://blog.csdn.net/hpccn") -- returns 3 parameters
JavaObjcet. methodOpen ("3", "different parameters", "http://blog.csdn.net/hpccn ")
End
Callback Interface
In the test, only the parameters passed in from Lua are output.
Package name: cn. hpc. common. lua
Class Name: LoadLibExample
Method Name: open
[Java]
Package cn. hpc. common. lua;
Import org. keplerproject. luajava. JavaFunction;
Import org. keplerproject. luajava. LuaException;
Import org. keplerproject. luajava. LuaState;
Public class LoadLibExample {
Public static int open (LuaState L) throws LuaException {
L. newTable ();
L. pushValue (-1 );
L. setGlobal ("javaObjcet ");
L. pushString ("methodOpen ");
L. pushJavaFunction (new JavaFunction (L ){
Public int execute () throws LuaException {
For (int I = 0, count = L. getTop () + 1; I <count; ++ I ){
System. out. println (getParam (I ));
}
Return 0;
}
});
L. setTable (-3 );
Return 1;
}
}
Running result, Log output:
[Plain]
11-19 11:12:32. 783: I/System. out (4137): Userdata
11-19 11:12:32. 783: I/System. out (4137): cn. hpc. common. lua. LoadLibExample $1 @ 2bc48890
11-19 11:12:32. 793: I/System. out (4137): 1.0
11-19 11:12:32. 793: I/System. out (4137):-4.0
11-19 11:12:32. 793: I/System. out (4137): Userdata
11-19 11:12:32. 793: I/System. out (4137): cn. hpc. common. lua. LoadLibExample $1 @ 2bc48890
11-19 11:12:32. 793: I/System. out (4137): 2.0
11-19 11:12:32. 793: I/System. out (4137): blog
11-19 11:12:32. 793: I/System. out (4137): http://blog.csdn.net/hpccn
11-19 11:12:32. 793: I/System. out (4137): Userdata
11-19 11:12:32. 793: I/System. out (4137): cn. hpc. common. lua. LoadLibExample $1 @ 2bc48890
11-19 11:12:32. 803: I/System. out (4137): 3.0
11-19 11:12:32. 803: I/System. out (4137): Different Parameters
11-19 11:12:32. 803: I/System. out (4137): http://blog.csdn.net/hpccn