I am also interested in knowing how to do this. The sample as the original poster pointed out is empty. Is there a technical limitation to implement this? Or this is just a case of missing sample. If it latter I would spend some time figuring it out if it the former then I can simply stop wasting my time. So far it is not obvious how to get this done.
I am also interested in knowing how to do this. The sample as the original poster pointed out is empty. Is there a technical limitation to implement this? Or this is just a case of missing sample. If it latter I would spend some time figuring it out if it the former then I can simply stop wasting my time. So far it is not obvious how to get this done.
I am also interested in the iOS implementation of the method asyncCallLuaFunction(). The iOS sample code is empty as iamarej and shneyderman pointed out.
static int asyncCallLuaFunction( lua\_State \*L ) { if ( lua\_isfunction( L, 1 ) ) { // Store a native reference to the Lua function parameter in the registry. // This allows us to use the Lua function in the block below. // // We must store a native reference, since the Lua function will not // be available beyond the scope of this native function. int functionRef = luaL\_ref( L, LUA\_REGISTRYINDEX ); // Use standard method for async invocation. // On iOS, Corona executes Lua code on the main thread, so we use the main queue. dispatch\_async( dispatch\_get\_main\_queue(), ^(void) { // Fetch Lua function from registry, and push to the top of the stack lua\_rawgeti( L, LUA\_REGISTRYINDEX, functionRef ); // Call the Lua function. // There are 0 arguments passed to this Lua function and 0 expected // results. lua\_call( L, 0, 0); // Remove the native reference to the Lua function from the registry, // so we don't leak. luaL\_unref( L, LUA\_REGISTRYINDEX, functionRef ); }); } return 0; }
On Android, we added CoronaRuntimeTask to provide you with a standard way to minimize race conditions since Lua does not execute on the main UI thread. On iOS, Lua does execute on the main UI thread, so we did not need to provide this level of encapsulation.
I am also interested in the iOS implementation of the method asyncCallLuaFunction(). The iOS sample code is empty as iamarej and shneyderman pointed out.
static int asyncCallLuaFunction( lua\_State \*L ) { if ( lua\_isfunction( L, 1 ) ) { // Store a native reference to the Lua function parameter in the registry. // This allows us to use the Lua function in the block below. // // We must store a native reference, since the Lua function will not // be available beyond the scope of this native function. int functionRef = luaL\_ref( L, LUA\_REGISTRYINDEX ); // Use standard method for async invocation. // On iOS, Corona executes Lua code on the main thread, so we use the main queue. dispatch\_async( dispatch\_get\_main\_queue(), ^(void) { // Fetch Lua function from registry, and push to the top of the stack lua\_rawgeti( L, LUA\_REGISTRYINDEX, functionRef ); // Call the Lua function. // There are 0 arguments passed to this Lua function and 0 expected // results. lua\_call( L, 0, 0); // Remove the native reference to the Lua function from the registry, // so we don't leak. luaL\_unref( L, LUA\_REGISTRYINDEX, functionRef ); }); } return 0; }
On Android, we added CoronaRuntimeTask to provide you with a standard way to minimize race conditions since Lua does not execute on the main UI thread. On iOS, Lua does execute on the main UI thread, so we did not need to provide this level of encapsulation.