Here you go. I’ve also filed a bug to get this code fleshed out generally. Note that the Lua API is really just C and not Objective-C so it’s simpler than the sample might make it appear and any Lua C API tutorial should help you.
static int printTableValuesXY( lua\_State \*L ) { int luaTableStackIndex = 1; if ( lua\_istable( L, luaTableStackIndex ) ) { // Print only the entry's "x" and "y" in the Lua table. // See the private method below on how to access an entry within a Lua table. NSLog( @"printTableValuesXY()"); NSLog( @"{"); NSLog( @" [x] = %@", getLuaTableEntryValueFrom(L, luaTableStackIndex, "x")); NSLog( @" [y] = %@", getLuaTableEntryValueFrom(L, luaTableStackIndex, "y")); NSLog( @"}"); } else { NSLog(@"printTableValuesXY: argument is not a table"); } // Return 0 since this Lua function does not return any values. return 0; } static NSString \* getLuaTableEntryValueFrom( lua\_State \*L, int stackIndex, const char \*name ) { NSString \*valueString = nil; lua\_getfield( L, -1, name ); if (lua\_isnumber( L, -1)) { valueString = [NSString stringWithFormat:@"%f", lua\_tonumber( L, -1 )]; } else { valueString = [NSString stringWithFormat:@"%s", lua\_tostring( L, -1 )]; } lua\_pop( L, 1 ); return valueString; }
This sample code is written in the style of the existing code and isn’t intended to represent best practices.