Where is iOS version of AsyncCallLuaFunction ?

Corona Enterprise provided good example of async callback on Android. (AsyncCallLuaFunction.java)

in the follwing sample project.

/Applications/CoronaEnterprise/Samples/SimpleLuaExtension

But correspondent version of iOS project doesn’t have implementation of async callback?

iOS version sample has only the following skeleton code.

static int asyncCallLuaFunction( lua_State *L ) {

    // TODO

    NSLog( @“asyncCallLuaFunction() not implemented” );

    return 0;

}

Would you please provide iOS version of acync callback sample code?

it’s in the same sample folder, for ios , go to the ios folder there should be a xcode project for it

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. 

it’s in the same sample folder, for ios , go to the ios folder there should be a xcode project for it

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.

We left this as an exercise for the reader :wink:

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; }

Hi,

Thanks for the code snippet.

But in android we get the fresh lua state object from the CoronaRuntimeTask.

com.ansca.corona.CoronaRuntimeTask task = new com.ansca.corona.CoronaRuntimeTask() {

  @Override

  public void executeUsing(com.ansca.corona.CoronaRuntime runtime) {

  // *** We are now running on the Corona runtime thread. ***

  try {

     // Fetch the Corona runtime’s Lua state.

      com.naef.jnlua.LuaState luaState = runtime.getLuaState();

}

What is the iOS equivalent of the CoronaRuntimeTask.

There’s no need for one on iOS.

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.

We left this as an exercise for the reader :wink:

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; }

Hi,

Thanks for the code snippet.

But in android we get the fresh lua state object from the CoronaRuntimeTask.

com.ansca.corona.CoronaRuntimeTask task = new com.ansca.corona.CoronaRuntimeTask() {

  @Override

  public void executeUsing(com.ansca.corona.CoronaRuntime runtime) {

  // *** We are now running on the Corona runtime thread. ***

  try {

     // Fetch the Corona runtime’s Lua state.

      com.naef.jnlua.LuaState luaState = runtime.getLuaState();

}

What is the iOS equivalent of the CoronaRuntimeTask.

There’s no need for one on iOS.

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.