Beispiel #1
0
//----------------------------------------------------------------//
void MOAIInputMgr::SetConfigurationName ( cc8* name ) {

	USLuaStateHandle state = USLuaRuntime::Get ().State ();
	this->PushLuaClassTable ( state );
	
	state.SetField ( -1, LUAVAR_CONFIGURATION, name );
}
Beispiel #2
0
//----------------------------------------------------------------//
void MOAIJoystickSensor::HandleEvent ( USStream& eventStream ) {

	this->mX = eventStream.Read < float >();
	this->mY = eventStream.Read < float >();
	
	if ( this->mOnStick ) {
		USLuaStateHandle state = this->mOnStick.GetSelf ();
		lua_pushnumber ( state, this->mX );
		lua_pushnumber ( state, this->mY );
		state.DebugCall ( 2, 0 );
	}
}
Beispiel #3
0
//----------------------------------------------------------------//
void MOAIScriptNode::OnDepNodeUpdate () {

	if ( this->mOnUpdate ) {
		
		USLuaStateHandle state = USLuaRuntime::Get ().State ();
		
		this->mOnUpdate.PushRef ( state );
		this->PushLuaUserdata ( state );

		state.DebugCall ( 1, 0 );
	}
}
Beispiel #4
0
//----------------------------------------------------------------//
void MOAIGfxDevice::SetSize ( u32 width, u32 height ) {

	this->mWidth = width;
	this->mHeight = height;
	
	USLuaStateHandle state = USLuaRuntime::Get ().State ();
	if ( this->PushListener ( EVENT_RESIZE, state )) {
		lua_pushnumber ( state, width );
		lua_pushnumber ( state, height );
		state.DebugCall ( 2, 0 );
	}
}
//----------------------------------------------------------------//
void MOAIMotionSensor::HandleEvent ( USStream& eventStream ) {

	this->mX = eventStream.Read < float >();
	this->mY = eventStream.Read < float >();
	this->mZ = eventStream.Read < float >();
	
	if ( this->mCallback ) {
		USLuaStateHandle state = this->mCallback.GetSelf ();
		lua_pushnumber ( state, this->mX );
		lua_pushnumber ( state, this->mY );
		lua_pushnumber ( state, this->mZ );
		state.DebugCall ( 3, 0 );
	}
}
//----------------------------------------------------------------//
void MOAIButtonSensor::HandleEvent ( USStream& eventStream ) {

	bool down = eventStream.Read < bool >();
	
	if ( down ) {
		this->mState |= IS_DOWN | DOWN;
	}
	else {
		this->mState &= ~IS_DOWN;
		this->mState |= UP;
	}
	
	if ( this->mOnButton ) {
		USLuaStateHandle state = this->mOnButton.GetSelf ();
		lua_pushboolean ( state, down );
		state.DebugCall ( 1, 0 );
	}
}
Beispiel #7
0
//----------------------------------------------------------------//
void USLuaRef::MakeWeak () {

	if ( this->mWeak ) return;
	if ( this->mRef == LUA_NOREF ) return;
	
	this->mWeak = true;
	
	if ( USLuaRuntime::IsValid ()) {

		USLuaRuntime& luaRuntime = USLuaRuntime::Get ();
		USLuaStateHandle state = luaRuntime.State ();

		luaRuntime.mStrongRefTable.PushRef ( state, this->mRef );
		luaRuntime.mStrongRefTable.Unref ( state, this->mRef );
		
		this->mRef = luaRuntime.mWeakRefTable.Ref ( state, -1 );
		state.Pop ( 1 );
	}
}
Beispiel #8
0
//----------------------------------------------------------------//
void MOAISim::RunString ( cc8* script ) {

	int status;
	USLuaStateHandle state = USLuaRuntime::Get ().State ();
	
	status = luaL_loadstring ( state, script );
	if ( state.PrintErrors ( status )) return;
	
	this->mRenderPasses.Clear ();
	MOAIActionMgr::Get ().Clear ();
	this->mTime = 0.0f;
	this->mDeviceTime = 0.0;
	
	state.DebugCall ( 0, 0 );

	AKUStartGameLoopFunc startGameLoop = AKUGetFunc_StartGameLoop ();
	if ( startGameLoop ) {
		startGameLoop ();
	}
}
Beispiel #9
0
//----------------------------------------------------------------//
u32 USLuaSerializer::SerializeFromFile ( cc8* filename ) {
	
	int status;
	USLuaStateHandle state = USLuaRuntime::Get ().State ();

	// load the lua file
	status = luaL_loadfile ( state, filename );
	if ( state.PrintErrors ( USLog::CONSOLE, status )) return LOAD_ERROR;
	
	// load self as the func param
	this->PushLuaUserdata ( state );
	
	// call the chunk
	if ( state.DebugCall ( 1, 0 )) return LUA_ERROR;
	
	lua_gc ( state, LUA_GCCOLLECT, 0 );
	
	// done!
	return SUCCESS;
}
Beispiel #10
0
//----------------------------------------------------------------//
void MOAILocationSensor::HandleEvent ( USStream& eventStream ) {

	this->mLongitude	= eventStream.Read < double >();
	this->mLatitude		= eventStream.Read < double >();
	this->mAltitude		= eventStream.Read < double >();
	this->mHAccuracy	= eventStream.Read < float >();
	this->mVAccuracy	= eventStream.Read < float >();
	this->mSpeed		= eventStream.Read < float >();
	
	if ( this->mCallback ) {
		USLuaStateHandle state = this->mCallback.GetSelf ();
		lua_pushnumber ( state, this->mLongitude );
		lua_pushnumber ( state, this->mLatitude );
		lua_pushnumber ( state, this->mHAccuracy );
		lua_pushnumber ( state, this->mAltitude );
		lua_pushnumber ( state, this->mVAccuracy );
		lua_pushnumber ( state, this->mSpeed );
		state.DebugCall ( 6, 0 );
	}
}
Beispiel #11
0
//----------------------------------------------------------------//
void MOAISim::RunFile ( cc8* filename ) {

	if ( !USFileSys::CheckFileExists ( filename )) return;

	int status;
	USLuaStateHandle state = USLuaRuntime::Get ().State ();
	
	status = luaL_loadfile ( state, filename );
	if ( state.PrintErrors ( status )) return;
	
	this->mRenderPasses.Clear ();
	MOAIActionMgr::Get ().Clear ();
	this->mTime = 0.0f;
	this->mDeviceTime = 0.0;
	
	state.DebugCall ( 0, 0 );

	AKUStartGameLoopFunc startGameLoop = AKUGetFunc_StartGameLoop ();
	if ( startGameLoop ) {
		startGameLoop ();
	}
}
Beispiel #12
0
//----------------------------------------------------------------//
void USLuaSerializer::WriteTableInits ( USStream& stream ) {

	if ( !this->mTableMap.size ()) return;

	stream.Print ( "\t--Initializing Tables\n" );
	stream.Print ( "\tlocal table\n\n" );

	USLuaStateHandle state = USLuaRuntime::Get ().State ();

	TableMapIt tableIt = this->mTableMap.begin ();
	for ( ; tableIt != this->mTableMap.end (); ++tableIt ) {
		
		uintptr tableID = tableIt->first;
		stream.Print ( "\ttable = objects [ 0x%08X ]\n", tableID );
		
		USLuaRef& tableRef = tableIt->second;
		state.Push ( tableRef );
		this->WriteTableInitializer ( stream, state, -1, "table" );
		state.Pop ( 1 );
		
		stream.Print ( "\n" );
	}
}