Пример #1
0
//=================================================================================
/*static*/ bool Node::ReadBoolean( lua_State* L, Context& context, const std::string& name, bool& value, bool defaultValue )
{
	value = defaultValue;
	lua_getfield( L, -1, name.c_str() );
	if( !lua_isnil( L, -1 ) && lua_isboolean( L, -1 ) )
		value = lua_toboolean( L, -1 ) ? true : false;
	else if( context.GetNodeReadingDisposition() == Context::NONEXISTENCE_OF_FIELD_IS_FATAL_ERROR )
	{
		lua_pop( L, 1 );
		return context.IssueError( "Failed to read boolean from field \"%s\".", name.c_str() );
	}
	lua_pop( L, 1 );
	return true;
}
Пример #2
0
//=================================================================================
/*static*/ bool Node::ReadRotorE3GA( lua_State* L, Context& context, const std::string& name, c3ga::rotorE3GA& rotor, const c3ga::rotorE3GA* defaultValue /*= 0*/ )
{
	bool success = false;
	int top = lua_gettop( L );

	try
	{
		if( defaultValue )
			rotor = *defaultValue;
		else
			rotor.set( c3ga::rotorE3GA::coord_scalar_e1e2_e2e3_e3e1, 1.0, 0.0, 0.0, 0.0 );

		lua_getfield( L, -1, name.c_str() );
		if( lua_isnil( L, -1 ) || !lua_istable( L, -1 ) )
		{
			if( context.GetNodeReadingDisposition() == Context::NONEXISTENCE_OF_FIELD_IS_FATAL_ERROR )
				throw Error( "ReadRotorE3GA failed to read \"%s\" as a table.", name.c_str() );
		}
		else
		{
			if( !ReadNumber( L, context, "scalar", rotor.m_scalar, 1.0 ) )
				throw new Error( "ReadRotorE3GA failed to read \"scalar\" from \"%s\".", name.c_str() );

			if( !ReadNumber( L, context, "xy", rotor.m_e1_e2, 0.0 ) )
				throw new Error( "ReadRotorE3GA failed to read \"xy\" from \"%s\".", name.c_str() );

			if( !ReadNumber( L, context, "yz", rotor.m_e2_e3, 0.0 ) )
				throw new Error( "ReadRotorE3GA failed to read \"yz\" from \"%s\".", name.c_str() );

			if( !ReadNumber( L, context, "zx", rotor.m_e3_e1, 0.0 ) )
				throw new Error( "ReadRotorE3GA failed to read \"zx\" from \"%s\".", name.c_str() );
		}

		lua_pop( L, 1 );

		success = true;
	}
	catch( Error* error )
	{
		context.IssueError( error );
	}

	lua_settop( L, top );

	return success;
}
Пример #3
0
//=================================================================================
/*static*/ bool Node::ReadVectorE2GA( lua_State* L, Context& context, const std::string& name, c3ga::vectorE2GA& vector, const c3ga::vectorE2GA* defaultValue /*= 0*/ )
{
	bool success = false;
	int top = lua_gettop( L );

	try
	{
		if( defaultValue )
			vector = *defaultValue;
		else
		{
			vector.set_e1( 0.0 );
			vector.set_e2( 0.0 );
		}

		lua_getfield( L, -1, name.c_str() );
		if( lua_isnil( L, -1 ) || !lua_istable( L, -1 ) )
		{
			if( context.GetNodeReadingDisposition() == Context::NONEXISTENCE_OF_FIELD_IS_FATAL_ERROR )
				throw new Error( "ReadVectorE2GA failed to read \"%s\" as a table.", name.c_str() );
		}
		else
		{
			if( !ReadNumber( L, context, "x", vector.m_e1, 0.0 ) )
				throw new Error( "ReadVectorE2GA failed to read \"x\" from \"%s\".", name.c_str() );

			if( !ReadNumber( L, context, "y", vector.m_e2, 0.0 ) )
				throw new Error( "ReadVectorE2GA failed to read \"y\" from \"%s\".", name.c_str() );
		}

		// Pop the vector table.
		lua_pop( L, 1 );

		success = true;
	}
	catch( Error* error )
	{
		context.IssueError( error );
	}

	lua_settop( L, top );

	return success;
}