We left this as an exercise for the reader
This is all possible using standard iOS techniques for async dispatch, combined with standard Lua techniques for referring to Lua values in native code:
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; }