Dear Rob,
I’m trying to call a Lua Function from Native Android.
I’m checking the SimpleLuaExtension Sample provided in Native.
But, I can’t figure where is configured the ‘myTest’,
For example, the lua code say:
function onCall() print("callLuaFunction() has succeeded Again") end myTests.callLuaFunction(onCall)
But, I’m turning crazy where and how can Lua know what to call when myTest is provided at the Lua code.
It is any internal not accesible reserved word ?
I’m trying the following:
/\*\* MY PLUGIN \*\*/ /\*\* \* The following Lua function has been called: library.pickFile( type ) \* \<p\> \* Warning! This method is not called on the main thread. \* @param L Reference to the Lua state that the Lua function was called from. \* @return Returns the number of values to be returned by the library.pickFile() function. \*/ @SuppressWarnings("WeakerAccess") public int pickFile (LuaState L) { // Fetch a reference to the Corona activity. // Note: Will be null if the end-user has just backed out of the activity. CoronaActivity activity = CoronaEnvironment.getCoronaActivity(); if (activity == null) { return 0; } // Fetch the first argument from the called Lua function. String mySetType = L.checkString(1); if (null == mySetType) { //All Files by Default. mySetType = "\*/\*"; } // Register your activity handler. int requestCode = activity.registerActivityResultHandler(new MyHandler()); int READ\_REQUEST\_CODE = requestCode; //Activity newActivity; Intent intent = new Intent .... activity.startActivityForResult(intent, requestCode); return 0; } private static class MyHandler implements CoronaActivity.OnActivityResultHandler { public MyHandler() {} @Override public void onHandleActivityResult( CoronaActivity activity, int requestCode, int resultCode, android.content.Intent data) { // Unregister this handler. activity.unregisterActivityResultHandler(this); // Handle the result... if (resultCode == Activity.RESULT\_OK) { //Call a Listener in Lua with the result parameters \<---- try { // Check if the first argument is a function. // Will throw an exception if not or if no argument is given. int luaFunctionStackIndex = 1; luaState.checkType(luaFunctionStackIndex, com.naef.jnlua.LuaType.FUNCTION); // Push the given Lua function to the top of the Lua state's stack. We need to do this because the // because the call() method below expects this Lua function to be a the top of the stack. luaState.pushValue(luaFunctionStackIndex); // Call the given Lua function. // The first argument indicates the number of arguments that we are passing to the Lua function. // The second argument indicates the number of return values to accept from the Lua function. // In this case, we are calling this Lua function with no arguments and are accepting no return values. // Note: If you want to call the Lua function with arguments, then you need to push each argument // value to the luaState object's stack. luaState.call(0, 0); } catch (Exception ex) { // An exception will occur if the following happens: // 1) No argument was given. // 2) The argument was not a Lua function. // 3) The Lua function call failed, likely because the Lua function could not be found. ex.printStackTrace(); } } // END\_INCLUDE (parse\_open\_document\_response) } } } /\*\* Implements the library.pickFile() Lua function. \*/ @SuppressWarnings("unused") private class pickFileWrapper implements NamedJavaFunction { /\*\* \* Gets the name of the Lua function as it would appear in the Lua script. \* @return Returns the name of the custom Lua function. \*/ @Override public String getName() { return "pickFile"; } /\*\* \* This method is called when the Lua function is called. \* \<p\> \* Warning! This method is not called on the main UI thread. \* @param L Reference to the Lua state. \* Needed to retrieve the Lua function's parameters and to return values back to Lua. \* @return Returns the number of values to be returned by the Lua function. \*/ @Override public int invoke(LuaState L) { return pickFile(L); } }
Dear, I don’t found the correct way to call a listener from Java to Lua. I need to return the values (uri, realPath…, ).
Can you illuminate me a little?
As mentioned, I have been checking the SimpleLuaExtension sample, and, I can’t figure how the Lua recognize the myTest without any require…
Thanks so much again,