Пример #1
0
static void _add_children_to_sbody(lua_State* L, CustomSBody* sbody, OOLUA::Lua_table children)
{
	int i=1;
	while (1) {
		CustomSBody *kid;

		if (!children.safe_at(i++, kid))
			break;

		if (kid == NULL) {
			luaL_error(L,
				"invalid element (must be CustomSBody or table of CustomSBody)\n"
				"invalid element is child of CustomSBody '%s'", sbody->name.c_str());
		}

		while (1) {
			OOLUA::Lua_table sub;

			if (!children.safe_at(i, sub))
				break;

			if (!sub.valid())
				break;

			_add_children_to_sbody(L, kid, sub);
			i++;
			continue;
		}

		sbody->children.push_back(*kid);
	}
}
Пример #2
0
	void copyConstruct_usingNewTable_orginalIsValid()
	{
		OOLUA::Lua_table orignal;
		OOLUA::new_table(*m_lua,orignal);
		OOLUA::Lua_table copy(orignal);

		CPPUNIT_ASSERT_EQUAL(true, orignal.valid() );
	}
Пример #3
0
	void tableSetValue_tableIsOnTop_afterCallStackHasOneEntry()
	{
		OOLUA::Lua_table t;
		OOLUA::new_table(*m_lua,t);
		t.push_on_stack(*m_lua);
		OOLUA::table_set_value(*m_lua,-1,"a",1);
		int stackSize = lua_gettop(*m_lua);
		CPPUNIT_ASSERT_EQUAL(1, stackSize );
	}
Пример #4
0
	void tableSetValue_tableIsOnTop_storedValueIsCorrect()
	{
		OOLUA::Lua_table t;
		OOLUA::new_table(*m_lua,t);
		t.push_on_stack(*m_lua);
		OOLUA::table_set_value(*m_lua,-1,"a",0);
		int storedValue(1);
		t.at("a",storedValue);
		lua_pop(*m_lua,1);
		CPPUNIT_ASSERT_EQUAL(0,storedValue );
	}
Пример #5
0
	void setValue_valueSetInLua_cppSideRepresentationHasChange()
	{
		OOLUA::Lua_table t;
		OOLUA::new_table(*m_lua,t);
		
		m_lua->run_chunk("func = function(t) t[\"a\"]=1; end");
		m_lua->call("func",t);
		
		int storedValue(0);
		t.at("a",storedValue);
		CPPUNIT_ASSERT_EQUAL(1, storedValue );
	}
Пример #6
0
CustomSystem::CustomSystem(std::string s, OOLUA::Lua_table t)
{
	name = s;

	numStars = 0;

	std::string stype;
	bool done = false;
	for (int i=0 ; i<4; i++) {
		int type = SBody::TYPE_GRAVPOINT;
		if (t.safe_at(i+1, stype)) {
			type = LuaConstants::GetConstant(csLua, "BodyType", stype.c_str());
			if ( type < SBody::TYPE_STAR_MIN || type > SBody::TYPE_STAR_MAX ) {
				printf("system star %d does not have a valid star type\n", i+1);
				assert(0);
			}
		}
		primaryType[i] = static_cast<SBody::BodyType>(type);

		if (type == SBody::TYPE_GRAVPOINT) done = true;
		if (!done) numStars++;
	}

	seed = 0;
	govType = Polit::GOV_NONE;
}
Пример #7
0
	void newTable_fromCplusplus_validReturnsTrue()
	{
		OOLUA::Lua_table t;
		OOLUA::new_table(*m_lua,t);
		CPPUNIT_ASSERT_EQUAL(true,t.valid() );
	}