/** @name init @text Initialize AdColony. @in string appId Available in AdColony dashboard settings. @in table zones A list of zones to configure. Available in AdColony dashboard settings. @out nil */ int MOAIAdColonyAndroid::_init ( lua_State* L ) { MOAILuaState state ( L ); cc8* identifier = lua_tostring ( state, 1 ); JNI_GET_ENV ( jvm, env ); JNI_GET_JSTRING ( identifier, jidentifier ); jobjectArray jzones = NULL; if ( state.IsType ( 2, LUA_TTABLE )) { int numEntries = 0; for ( int key = 1; ; ++key ) { state.GetField ( 2, key ); cc8* value = _luaParseTable ( state, -1 ); lua_pop ( state, 1 ); if ( !value ) { numEntries = key - 1; break; } } jzones = env->NewObjectArray ( numEntries, env->FindClass( "java/lang/String" ), 0 ); for ( int key = 1; ; ++key ) { state.GetField ( 2, key ); cc8* value = _luaParseTable ( state, -1 ); lua_pop ( state, 1 ); if ( value ) { JNI_GET_JSTRING ( value, jvalue ); env->SetObjectArrayElement ( jzones, key - 1, jvalue ); } else { break; } } } if ( jzones == NULL ) { jzones = env->NewObjectArray ( 0, env->FindClass( "java/lang/String" ), 0 ); } jclass adcolony = env->FindClass ( "com/ziplinegames/moai/MoaiAdColony" ); if ( adcolony == NULL ) { ZLLog::Print ( "MOAIAdColonyAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiAdColony" ); } else { jmethodID init = env->GetStaticMethodID ( adcolony, "init", "(Ljava/lang/String;[Ljava/lang/String;)V" ); if ( init == NULL ) { ZLLog::Print ( "MOAIAdColonyAndroid: Unable to find static java method %s", "init" ); } else { env->CallStaticVoidMethod ( adcolony, init, jidentifier, jzones ); } } return 0; }
/** @name login @text Prompt the user to login to Facebook. @opt table permissions Optional set of required permissions. See Facebook documentation for a full list. Default is nil. @out nil */ int MOAIFacebookAndroid::_login ( lua_State *L ) { MOAILuaState state ( L ); JNI_GET_ENV ( jvm, env ); jobjectArray jpermissions = NULL; if ( state.IsType ( 1, LUA_TTABLE )) { int numEntries = 0; for ( int key = 1; ; ++key ) { state.GetField ( 1, key ); cc8* value = _luaParseTable ( state, -1 ); lua_pop ( state, 1 ); if ( !value ) { numEntries = key - 1; break; } } jpermissions = env->NewObjectArray ( numEntries, env->FindClass( "java/lang/String" ), 0 ); for ( int key = 1; ; ++key ) { state.GetField ( 1, key ); cc8* value = _luaParseTable ( state, -1 ); lua_pop ( state, 1 ); if ( value ) { JNI_GET_JSTRING ( value, jvalue ); env->SetObjectArrayElement ( jpermissions, key - 1, jvalue ); } else { break; } } } if ( jpermissions == NULL ) { jpermissions = env->NewObjectArray ( 0, env->FindClass( "java/lang/String" ), 0 ); } jclass facebook = env->FindClass ( "com/ziplinegames/moai/MoaiFacebook" ); if ( facebook == NULL ) { ZLLog::Print ( "MOAIFacebookAndroid: Unable to find java class %s", "com/ziplinegames/moai/MoaiFacebook" ); } else { jmethodID login = env->GetStaticMethodID ( facebook, "login", "([Ljava/lang/String;)V" ); if ( login == NULL ) { ZLLog::Print ( "MOAIFacebookAndroid: Unable to find static java method %s", "login" ); } else { env->CallStaticVoidMethod ( facebook, login, jpermissions ); } } return 0; }