예제 #1
0
int MOAIFmodEventMgr::_playEvent2D ( lua_State* L ) {
    MOAILuaState state ( L );

    cc8* eventName = state.GetValue < cc8* > ( 1, "" );
    if ( eventName[0] != '\0' ) {
        
        const FMODDesigner::Event* pEvent = MOAIFmodEventMgr::Get().GetEvent( eventName );
        if ( !pEvent )
        {
            FMODDesigner::Event actualEvent = FMODDesigner::Event( STLString( eventName ) );
            MOAIFmodEventMgr::Get().AddEvent( eventName, actualEvent );
            pEvent = MOAIFmodEventMgr::Get().GetEvent( eventName );
        }
        
        
        if ( pEvent->IsValid() ) {
            bool bLoop = state.GetValue( 2, false );
            
            // Try to play the sound
            FMODDesigner::EventHandle hEventHandle = FMODDesigner::tEventManager.PlayEvent2D( *pEvent, bLoop );

            // Create a MOAI Event Instance and push it out
            MOAIFmodEventInstance* pEventInstance = new MOAIFmodEventInstance();
            pEventInstance->SetEventInstance( hEventHandle );   

            pEventInstance->PushLuaUserdata ( state );

            return 1;
        }        
    }
     
    return 0;
}
예제 #2
0
/**	@name	getMaxTextureUnits
	@text	Returns the frame buffer associated with the device.

	@out	MOAIFrameBuffer frameBuffer
*/
int MOAIGfxDevice::_getFrameBuffer ( lua_State* L ) {

	MOAILuaState state ( L );
	state.Push ( MOAIGfxDevice::Get ().GetDefaultBuffer ());

	return 1;
}
예제 #3
0
파일: GIIHelper.cpp 프로젝트: pixpil/gii
int GIIHelper::_stepSim( lua_State *L ){
	MOAILuaState state (L);
	if ( !state.CheckParams ( 1, "N" )) return 0;
	double step = state.GetValue< double >( 1, 0.0f );
	GIIHelper::Get().stepSim( step );
	return 0;
}
예제 #4
0
파일: GIIHelper.cpp 프로젝트: pixpil/gii
int GIIHelper::_renderFrameBuffer( lua_State *L ){
	MOAILuaState state (L);
	if ( !state.CheckParams ( 1, "U" )) return 0;
	MOAIFrameBufferRenderCommand* command = state.GetLuaObject < MOAIFrameBufferRenderCommand >( -1, false );
	if ( command ) {
		if ( command->IsEnabled() && command->GetFrameBuffer() ) {
			zglBegin();
			command->Render();
			zglEnd();
		}
	} else {
		MOAIFrameBuffer* frameBuffer = state.GetLuaObject < MOAIFrameBuffer >( -1, false );
		if ( frameBuffer ) {
			zglBegin();
			frameBuffer->Render ( NULL );
			zglEnd();
		}
	}
	// MOAIFrameBuffer* frameBuffer = state.GetLuaObject < MOAIFrameBuffer >( 1, false );
	// MOAIGfxDevice& device = MOAIGfxDevice::Get ();
	// if (frameBuffer) {
	// 	zglBegin();
	// 	frameBuffer->Render( NULL );
	// 	zglEnd();
	// }
	return 0;
}
예제 #5
0
//----------------------------------------------------------------//
void MOAIFacebookAndroid::RegisterLuaClass ( MOAILuaState& state ) {

	state.SetField ( -1, "DIALOG_DID_COMPLETE",		( u32 ) DIALOG_DID_COMPLETE );
	state.SetField ( -1, "DIALOG_DID_NOT_COMPLETE",	( u32 ) DIALOG_DID_NOT_COMPLETE );
	state.SetField ( -1, "SESSION_DID_LOGIN",		( u32 ) SESSION_DID_LOGIN );
	state.SetField ( -1, "SESSION_DID_NOT_LOGIN",	( u32 ) SESSION_DID_NOT_LOGIN );
	
	luaL_Reg regTable [] = {
		{ "getExpirationDate", _getExpirationDate },	
		{ "getToken",		_getToken },
		{ "graphRequest",	_graphRequest },
		{ "init",			_init },
		{ "login",			_login },
		{ "logout",			_logout },
		{ "postToFeed",		_postToFeed },
		{ "sendRequest",	_sendRequest },
		{ "sessionValid",	_sessionValid },
		{ "setListener",	_setListener },
		{ "setToken",		_setToken },
		{ "extendToken",	_extendToken },
		{ "setExpirationDate", _setExpirationDate },		
		{ NULL, NULL }
	};

	luaL_register ( state, 0, regTable );
}
예제 #6
0
/**
 * Create a jobjectArray from the Lua stack
 * @param lua_state The lua Stack
 * @param index The index to convert
 */
jobjectArray JniUtils::arrayFromLua ( lua_State* L, int index ) {
    MOAILuaState state ( L );
	JNI_GET_ENV ( jvm, env );

    int numEntries = 0;
    for ( int key = 1; ; ++key ) {
        state.GetField ( 1, key );
        cc8* value = JniUtils::parseLuaTable ( state, -1 );
        lua_pop ( state, 1 );

        if ( !value ) {
            numEntries = key - 1;
            break;
        }
    }

    jobjectArray array = env->NewObjectArray ( numEntries, env->FindClass( "java/lang/String" ), 0 );
    for ( int key = 1; ; ++key ) {

        state.GetField ( 1, key );
        cc8* value = JniUtils::parseLuaTable ( state, -1 );
        lua_pop ( state, 1 );

        if ( value ) {
            JNI_GET_JSTRING ( value, jvalue );
            env->SetObjectArrayElement ( array, key - 1, jvalue );
        }
        else {
            break;
        }
    }
    return array;
}
예제 #7
0
//----------------------------------------------------------------//
uintptr MOAISerializer::AffirmMemberID ( MOAILuaState& state, int idx ) {

	// if we're an object, affirm as such...
	if ( state.IsType ( idx, LUA_TUSERDATA )) {
		return this->AffirmMemberID ( state.GetLuaObject < MOAILuaObject >( -1 ));
	}

	// bail if we're not a table
	if ( !state.IsType ( idx, LUA_TTABLE )) return 0;

	// get the table's address
	uintptr memberID = ( uintptr )lua_topointer ( state, idx );
	
	// bail if the table's already been added
	if ( this->mTableMap.contains ( memberID )) return memberID;

	// add the ref now to avoid cycles
	this->mTableMap [ memberID ].SetStrongRef ( state, idx );

	// follow the table's refs to make sure everything gets added
	u32 itr = state.PushTableItr ( idx );
	while ( state.TableItrNext ( itr )) {
		this->AffirmMemberID ( state, -1 );
	}
	
	return memberID;
}
예제 #8
0
/**	@name	setClearColor
	@text	At the start of each frame the device will by default automatically render a background color.  Using this function you can set the background color that is drawn each frame.  If you specify no arguments to this function, then automatic redraw of the background color will be turned off (i.e. the previous render will be used as the background).

	@overload

		@opt	number red			The red value of the color.
		@opt	number green		The green value of the color.
		@opt	number blue			The blue value of the color.
		@opt	number alpha		The alpha value of the color.
		@out	nil
	
	@overload
	
		@in		MOAIColor color
		@out	nil
*/
int MOAIGfxDevice::_setClearColor ( lua_State* L ) {

	MOAILuaState state ( L );
	MOAIGfxDevice& device = MOAIGfxDevice::Get ();
	
	MOAIColor* color = state.GetLuaObject < MOAIColor >( 1 );
	if ( color ) {
		device.SetClearColor ( color );
		device.mClearFlags |= GL_COLOR_BUFFER_BIT;
		return 0;
	}
	
	// don't clear the color
	device.mClearFlags &= ~GL_COLOR_BUFFER_BIT;
	device.SetClearColor ( 0 );

	if ( state.GetTop () > 0 ) {
	
		float r = state.GetValue < float >( 1, 0.0f );
		float g = state.GetValue < float >( 2, 0.0f );
		float b = state.GetValue < float >( 3, 0.0f );
		float a = state.GetValue < float >( 4, 1.0f );
		
		device.mClearColor = USColor::PackRGBA ( r, g, b, a );
		device.mClearFlags |= GL_COLOR_BUFFER_BIT;
	}
	return 0;
}
예제 #9
0
//----------------------------------------------------------------//
void MOAILogMgr::LogVar ( lua_State *L, u32 messageID, va_list args ) {

	if ( this->mLevel ) {

		MessageMapIt messageMapIt = this->mMessageMap.find ( messageID );
		if ( messageMapIt != this->mMessageMap.end ()) {
		
			MOAILogMessage& message = messageMapIt->second;
			
			if ( message.mLevel <= this->mLevel ) {
				
				if ( L ) {
					this->Print ( "----------------------------------------------------------------\n" );
				}
				
				this->PrintVar ( message.mFormatString, args );
				this->Print ( "\n" );
				
				if ( L ) {
					MOAILuaState state ( L );
					state.PrintStackTrace ( this->mFile, 0 );
					this->Print ( "\n" );
				}
			}
		}
	}
}
예제 #10
0
파일: MOAIApp.cpp 프로젝트: Heyzap/moai-dev
//----------------------------------------------------------------//
void MOAIApp::RegisterLuaClass ( MOAILuaState& state ) {

	state.SetField ( -1, "PAYMENT_QUEUE_TRANSACTION",	( u32 )PAYMENT_QUEUE_TRANSACTION );
	state.SetField ( -1, "PAYMENT_QUEUE_ERROR",			( u32 )PAYMENT_QUEUE_ERROR );
	state.SetField ( -1, "PRODUCT_REQUEST_RESPONSE",	( u32 )PRODUCT_REQUEST_RESPONSE );
	
	state.SetField ( -1, "DOMAIN_DOCUMENTS",			( u32 )DOMAIN_DOCUMENTS );
	state.SetField ( -1, "DOMAIN_APP_SUPPORT",			( u32 )DOMAIN_APP_SUPPORT );

	state.SetField ( -1, "TRANSACTION_STATE_PURCHASING",( u32 )TRANSACTION_STATE_PURCHASING );
	state.SetField ( -1, "TRANSACTION_STATE_PURCHASED", ( u32 )TRANSACTION_STATE_PURCHASED );
	state.SetField ( -1, "TRANSACTION_STATE_FAILED",    ( u32 )TRANSACTION_STATE_FAILED );
	state.SetField ( -1, "TRANSACTION_STATE_RESTORED",  ( u32 )TRANSACTION_STATE_RESTORED );
	state.SetField ( -1, "TRANSACTION_STATE_CANCELLED", ( u32 )TRANSACTION_STATE_CANCELLED );
	
	luaL_Reg regTable[] = {
		{ "alert",								_alert },

		{ "canMakePayments",					_canMakePayments },
		{ "restoreCompletedTransactions",		_restoreCompletedTransactions },
		{ "requestPaymentForProduct",			_requestPaymentForProduct },
		{ "requestProductIdentifiers",			_requestProductIdentifiers },

		{ "setListener",						_setListener },
		{ "getDirectoryInDomain",				_getDirectoryInDomain },
		{ "openURL",							_openURL },
		{ "openURLPOP",							_openURLPOP },
		{ NULL, NULL }
	};

	luaL_register( state, 0, regTable );
}
예제 #11
0
//----------------------------------------------------------------//
void MOAIMesh::SerializeIn ( MOAILuaState& state, MOAIDeserializer& serializer ) {

	MOAIVertexArray::SerializeIn ( state, serializer );

	this->SetIndexBuffer ( serializer.MemberIDToObject < MOAIIndexBuffer >( state.GetField < MOAISerializer::ObjID >( -1, "mIndexBuffer", 0 )));
	
	this->mTotalElements = state.GetField < u32 >( -1, "mTotalElements", 0 );
	
	this->mHasBounds = state.GetField < bool >( -1, "mHasBounds", 0 );
	
	if ( state.GetFieldWithType ( -1, "mBounds", LUA_TTABLE )) {
		
		this->mBounds.mMin.mX	= state.GetField < float >( -1, "mMinX", 0 );
		this->mBounds.mMin.mY	= state.GetField < float >( -1, "mMinY", 0 );
		this->mBounds.mMin.mZ	= state.GetField < float >( -1, "mMinZ", 0 );
		
		this->mBounds.mMax.mX	= state.GetField < float >( -1, "mMaxX", 0 );
		this->mBounds.mMax.mY	= state.GetField < float >( -1, "mMaxY", 0 );
		this->mBounds.mMax.mZ	= state.GetField < float >( -1, "mMaxZ", 0 );
		
		state.Pop ();
	}
	
	this->mPenWidth = state.GetField < float >( -1, "mPenWidth", 0 );
}
예제 #12
0
int MOAIFmodEventMgr::_unloadPendingUnloads ( lua_State* L ) {
    MOAILuaState state ( L );

    bool bBlockOnUnload = state.GetValue ( 1, false );
    FMODDesigner::tEventManager.UnloadPendingUnloads( bBlockOnUnload );
     
    return 0;
}
예제 #13
0
파일: GIIHelper.cpp 프로젝트: pixpil/gii
int GIIHelper::_setBufferSize( lua_State *L){
	MOAILuaState state (L);
	if ( !state.CheckParams ( 1, "NN" )) return 0;
	u32 width=state.GetValue<u32>(1, 0);
	u32 height=state.GetValue<u32>(2, 0);
	MOAIGfxDevice::Get ().SetBufferSize ( width, height );
	return 0;
}
예제 #14
0
//----------------------------------------------------------------//
void MOAIParticleForce::RegisterLuaClass ( MOAILuaState& state ) {

	this->MOAITransform::RegisterLuaClass ( state );
	
	state.SetField ( -1, "FORCE", ( u32 )FORCE );
	state.SetField ( -1, "GRAVITY", ( u32 )GRAVITY );
	state.SetField ( -1, "OFFSET", ( u32 )OFFSET );
}
예제 #15
0
//----------------------------------------------------------------//
int MOAILuaRuntime::_debugCall ( lua_State* L ) {

	MOAILuaState state ( L );

	state.DebugCall ( 0, 0 );

	return 0;
}
예제 #16
0
//----------------------------------------------------------------//
// TODO: doxygen
int MOAIVertexFormatMgr::_getFormat ( lua_State* L ) {
	MOAILuaState state ( L );

	u32 formatID = state.GetValue < u32 >( 1, 0xffffffff );
	
	state.Push ( MOAIVertexFormatMgr::Get ().GetFormat ( formatID ));
	return 1;
}
예제 #17
0
파일: GIIHelper.cpp 프로젝트: pixpil/gii
int GIIHelper::_setVertexTransform( lua_State *L){
	MOAILuaState state (L);
	if ( !state.CheckParams ( 1, "U" )) return 0;
	MOAITransformBase* trans = state.GetLuaObject< MOAITransformBase >(1, true);
	if ( trans ) {
		MOAIGfxDevice::Get().SetVertexTransform( MOAIGfxDevice::VTX_WORLD_TRANSFORM, trans->GetLocalToWorldMtx() );
	}
	return 0;
}
예제 #18
0
//----------------------------------------------------------------//
void MOAIVertexFormat::RegisterLuaClass ( MOAILuaState& state ) {
	
	state.SetField ( -1, "GL_BYTE", ( u32 )ZGL_TYPE_BYTE );
	//state.SetField ( -1, "GL_FIXED", ( u32 )GL_FIXED );
	state.SetField ( -1, "GL_FLOAT", ( u32 )ZGL_TYPE_FLOAT );
	state.SetField ( -1, "GL_SHORT", ( u32 )ZGL_TYPE_SHORT );
	state.SetField ( -1, "GL_UNSIGNED_BYTE", ( u32 )ZGL_TYPE_UNSIGNED_BYTE );
	state.SetField ( -1, "GL_UNSIGNED_SHORT", ( u32 )ZGL_TYPE_UNSIGNED_SHORT );
}
예제 #19
0
/**	@name	openFile
	@text	Opens a new file to receive log messages.
	
	@in		string filename
	@out	nil
*/
int MOAILogMgr::_openFile ( lua_State* L ) {

	MOAILuaState state ( L );
	if ( !state.CheckParams ( 1, "S" )) return 0;
	
	cc8* filename = state.GetValue < cc8* >( 1, "" );
	MOAILogMgr::Get ().OpenFile ( filename );
	
	return 0;
}
예제 #20
0
/**	@name	log
	@text	Alias for print.
	
	@in		string message
	@out	nil
*/
int MOAILogMgr::_log ( lua_State* L ) {

	MOAILuaState state ( L );
	if ( !state.CheckParams ( 1, "S" )) return 0;

	cc8* msg = state.GetValue < cc8* >( 1, "" );
	ZLLog::Print( msg );
	
	return 0;
}
예제 #21
0
//----------------------------------------------------------------//
void MOAIAnimCurve::RegisterLuaClass ( MOAILuaState& state ) {

	state.SetField ( -1, "ATTR_TIME", MOAIAnimCurveAttr::Pack ( ATTR_TIME ));
	state.SetField ( -1, "ATTR_VALUE", MOAIAnimCurveAttr::Pack ( ATTR_VALUE ));

	state.SetField ( -1, "CLAMP", ( u32 ) CLAMP );
	state.SetField ( -1, "WRAP", ( u32 ) WRAP );
	state.SetField ( -1, "MIRROR", ( u32 ) MIRROR );
	state.SetField ( -1, "APPEND", ( u32 ) APPEND );
}
예제 #22
0
/**	@name	areaForRect
	@text	Returns the area for the specified rectangle.

	@in		number x1
	@in		number y1
	@in		number x2
	@in		number y2
	@out	number area			The calculated area.
*/
int MOAICpShape::_areaForRect ( lua_State* L ) {
	MOAILuaState state ( L );
	if ( !state.CheckParams ( 1, "NNNN" )) return 0;

	ZLMetaRect < cpFloat > rect = state.GetRect < cpFloat >( 1 );
	rect.Bless ();
	
	lua_pushnumber ( L, rect.Area ());
	return 1;
}
예제 #23
0
/**	@name	setValue
	@text	Sets an environment value and also triggers the listener
			callback (if any).

	@in		string key
	@opt	variant value		Default value is nil.
	@out	nil
*/
int MOAIEnvironment::_setValue ( lua_State* L ) {
	MOAILuaState state ( L );
	
	if ( state.IsType ( 1, LUA_TSTRING )) {
	
		MOAIEnvironment& environment = MOAIEnvironment::Get ();
		environment.SetValue ( state );
	}
	return 0;
}
예제 #24
0
//----------------------------------------------------------------//
void MOAIGlyph::SerializeOut ( MOAILuaState& state ) {

    state.SetField ( -1, "mCode", this->mCode );
    state.SetField ( -1, "mPageID", this->mPageID );

    state.SetField ( -1, "mWidth", this->mWidth );
    state.SetField ( -1, "mHeight", this->mHeight );
    state.SetField ( -1, "mAdvanceX", this->mAdvanceX );
    state.SetField ( -1, "mBearingX", this->mBearingX );
    state.SetField ( -1, "mBearingY", this->mBearingY );

    state.SetField ( -1, "mSrcX", this->mSrcX );
    state.SetField ( -1, "mSrcY", this->mSrcY );

    if ( this->mKernTable.Size ()) {
        lua_newtable ( state );
        for ( u32 i = 0; i < this->mKernTable.Size (); ++i ) {

            lua_pushnumber ( state, i + 1 );
            lua_newtable ( state );

            state.SetField ( -1, "mName", this->mKernTable [ i ].mName );
            state.SetField ( -1, "mX", this->mKernTable [ i ].mX );
            state.SetField ( -1, "mY", this->mKernTable [ i ].mY );

            lua_settable ( state, -3 );
        }
        lua_setfield ( state, -2, "mKernTable" );
    }
}
예제 #25
0
//----------------------------------------------------------------//
int MOAILuaObject::_tombstone ( lua_State* L ) {

	MOAILuaState state ( L );
	
	ZLLog::Print ( "----------------------------------------------------------------\n" );
	ZLLog::Print ( "ERROR: Attempt to access missing object instance.\n" );
	state.PrintStackTrace ( ZLLog::CONSOLE, 0 );
	ZLLog::Print ( "\n" );
	
	return 0;
}
예제 #26
0
//----------------------------------------------------------------//
int MOAILuaObject::_getClassName ( lua_State* L ) {

	MOAILuaState state ( L );
	MOAILuaObject* object = ( MOAILuaObject* )state.GetPtrUserData ( 1 );

	if ( object ) {
		lua_pushstring ( L, object->TypeName ());
		return 1;
	}
	return 0;
}
예제 #27
0
//----------------------------------------------------------------//
int MOAILuaObject::_getClass ( lua_State* L ) {

	MOAILuaState state ( L );
	MOAILuaObject* object = ( MOAILuaObject* )state.GetPtrUserData ( 1 );

	if ( object ) {
		object->PushLuaClassTable ( state );
		return 1;
	}
	return 0;
}
예제 #28
0
//----------------------------------------------------------------//
bool MOAILuaObject::IsMoaiUserdata ( MOAILuaState& state, int idx ) {

	bool result = false;
	if ( state.IsType ( idx, LUA_TUSERDATA )) {
		if ( lua_getmetatable ( state, idx )) {
			result = state.HasField ( -1, MOAI_TAG );
			state.Pop ( 1 );
		}
	}
	return result;
}
예제 #29
0
/**	@name	timeToFrames
	@text	Converts the number of time passed in seconds to frames.

	@in		number time			The number of seconds.
	@out	number frames		The equivilant number of frames for the specified number of seconds.
*/
int MOAISim::_timeToFrames ( lua_State* L ) {

	MOAILuaState state ( L );
	if ( !state.CheckParams ( 1, "N" )) return 0;
	
	float time = state.GetValue < float >( 1, 0.0f );
	
	MOAISim& device = MOAISim::Get ();
	lua_pushnumber ( state, time / device.mStep );
	
	return 1;
}
예제 #30
0
/**	@name	framesToTime
	@text	Converts the number of frames to time passed in seconds.

	@in		number frames		The number of frames.
	@out	number time			The equivilant number of seconds for the specified number of frames.
*/
int MOAISim::_framesToTime ( lua_State* L ) {

	MOAILuaState state ( L );
	if ( !state.CheckParams ( 1, "N" )) return 0;
	
	float frames = state.GetValue < float >( 1, 0.0f );
	
	MOAISim& device = MOAISim::Get ();
	lua_pushnumber ( state, frames * device.mStep );
	
	return 1;
}