예제 #1
0
static int _get_stage_durations(lua_State *L, const char *key, int &outNumStages, double **outDurationArray)
{
	LUA_DEBUG_START(L);
	LuaTable stages = LuaTable(L, -1).Sub(key);
	if (stages.GetLua() == 0) {
		luaL_error(L, "Not a proper table (%s)", key);
	}
	if (stages.Size() < 1)
		return luaL_error(L, "Station must have at least 1 stage in %s", key);
	outNumStages = stages.Size();
	*outDurationArray = new double[stages.Size()];
	std::copy(stages.Begin<double>(), stages.End<double>(), *outDurationArray);
	lua_pop(L, 1); // Popping t
	LUA_DEBUG_END(L, 0);
	return 0;
}
예제 #2
0
// Data format example:
//	bay_groups = {
//		{0, 500, {1}},
//	},
static int _get_bay_ids(lua_State *L, const char *key, SpaceStationType::TBayGroups &outBayGroups, unsigned int &outNumDockingPorts)
{
	LUA_DEBUG_START(L);
	LuaTable t = LuaTable(L, -1).Sub(key);
	if (t.GetLua() == 0) {
		luaL_error(L, "The bay group isn't a proper table (%s)", key);
	}
	if (t.Size() < 1) {
		return luaL_error(L, "Station must have at least 1 group of bays in %s", key);
	}

	LuaTable::VecIter<LuaTable> it_end = t.End<LuaTable>();
	for (LuaTable::VecIter<LuaTable> it = t.Begin<LuaTable>(); it != it_end; ++it) {
		SpaceStationType::SBayGroup newBay;
		newBay.minShipSize = it->Get<int>(1);
		newBay.maxShipSize = it->Get<int>(2);
		LuaTable group = it->Sub(3);

		if (group.GetLua() == 0) {
			luaL_error(L, "A group is of the form {int, int, table} (%s)", key);
		}

		if (group.Size() == 0) {
			return luaL_error(L, "Group must have at least 1 bay %s", key);
		}

		newBay.bayIDs.reserve(group.Size());
		LuaTable::VecIter<int> jt_end = group.End<int>();
		for (LuaTable::VecIter<int> jt = group.Begin<int>(); jt != jt_end; ++jt) {
			if ((*jt) < 1) {
				return luaL_error(L, "Valid bay ID ranges start from 1 %s", key);
			}
			newBay.bayIDs.push_back((*jt)-1);
			++outNumDockingPorts;
		}
		lua_pop(L, 1); // Popping group
		outBayGroups.push_back(newBay);
	}
	lua_pop(L, 1); // Popping t
	LUA_DEBUG_END(L, 0);
	return 0;
}