Esempio n. 1
28
xr_string to_string					(luabind::object const& o)
{
	using namespace luabind;
	if (o.type() == LUA_TSTRING) return object_cast<xr_string>(o);
	lua_State* L = o.lua_state();
	LUABIND_CHECK_STACK(L);

#ifdef BOOST_NO_STRINGSTREAM
	std::strstream s;
#else
	std::stringstream s;
#endif

	if (o.type() == LUA_TNUMBER)
	{
		s << object_cast<float>(o);
		return xr_string(s.str().c_str());
	}

	s << "<" << lua_typename(L, o.type()) << ">";
#ifdef BOOST_NO_STRINGSTREAM
	s << std::ends;
#endif
	return s.str().c_str();
}
void parse_table	(luabind::object const &table, LPCSTR identifier, luabind::object &result)
{
	VERIFY2			(table.type() == LUA_TTABLE, "invalid loophole description passed");
	result			= table[identifier];
	VERIFY2			(result.type() != LUA_TNIL, make_string("cannot read table value %s", identifier));
	VERIFY2			(result.type() == LUA_TTABLE, make_string("cannot read table value %s", identifier));
}
void smart_cover::action::add_animation(LPCSTR type, luabind::object const &table)
{	
	VERIFY						( table.type() == LUA_TTABLE );
	luabind::object::iterator I	= table.begin();
	luabind::object::iterator E	= table.end();
	Animations* animations		= xr_new<Animations>( );
	for ( ; I != E; ++I) {
		luabind::object	string	= *I;
		if (string.type() != LUA_TSTRING) {
			VERIFY				( string.type() != LUA_TNIL );
			continue;
		}

		shared_str animation	= luabind::object_cast<LPCSTR>(string);
		VERIFY2					(
			std::find(
				animations->begin(),
				animations->end(),
				animation
			) == 
			animations->end(),
			make_string(
				"duplicated_animation found: %s",
				animation.c_str()
			)
		);
		animations->push_back	( animation );
	}

	m_animations.insert			( std::make_pair( type, animations ) );
}
Fvector parse_fvector (luabind::object const &table, LPCSTR identifier)
{
	VERIFY2			(table.type() == LUA_TTABLE, "invalid loophole description passed");
	luabind::object	result = table[identifier];
	VERIFY2			(result.type() != LUA_TNIL, make_string("cannot read vector value %s", identifier));
	return			(luabind::object_cast<Fvector>(result));
}
Esempio n. 5
0
xr_string member_to_string			(luabind::object const& e, LPCSTR function_signature)
{
#if !defined(LUABIND_NO_ERROR_CHECKING3)
    using namespace luabind;
	lua_State* L = e.lua_state();
	LUABIND_CHECK_STACK(L);

	if (e.type() == LUA_TFUNCTION)
	{
		e.pushvalue();
		detail::stack_pop p(L, 1);

		{
			if (lua_getupvalue(L, -1, 3) == 0) return to_string(e);
			detail::stack_pop p2(L, 1);
			if (lua_touserdata(L, -1) != reinterpret_cast<void*>(0x1337)) return to_string(e);
		}

#ifdef BOOST_NO_STRINGSTREAM
		std::strstream s;
#else
		std::stringstream s;
#endif
		{
			lua_getupvalue(L, -1, 2);
			detail::stack_pop p2(L, 1);
		}

		{
			lua_getupvalue(L, -1, 1);
			detail::stack_pop p2(L, 1);
			detail::method_rep* m = static_cast<detail::method_rep*>(lua_touserdata(L, -1));

			for (std::vector<detail::overload_rep>::const_iterator i = m->overloads().begin();
				i != m->overloads().end(); ++i)
			{
				xr_string str;
				i->get_signature(L, str);
				if (i != m->overloads().begin())
					s << "\n";
				s << function_signature << process_signature(str) << ";";
			}
		}
#ifdef BOOST_NO_STRINGSTREAM
		s << std::ends;
#endif
		return s.str().c_str();
	}

    return to_string(e);
#else
    return "";
#endif
}
float parse_float	(
					 luabind::object const &table,
					 LPCSTR identifier,
					 float const &min_threshold = flt_min,
					 float const &max_threshold = flt_max
					 )
{
	VERIFY2			(table.type() == LUA_TTABLE, "invalid loophole description passed");
	luabind::object	lua_result = table[identifier];
	VERIFY2			(lua_result.type() != LUA_TNIL, make_string("cannot read number value %s", identifier));
	VERIFY2			(lua_result.type() == LUA_TNUMBER, make_string("cannot read number value %s", identifier));
	float			result = luabind::object_cast<float>(lua_result);
	VERIFY2			(result >= min_threshold, make_string("invalid read number value %s", identifier));
	VERIFY2			(result <= max_threshold, make_string("invalid number value %s", identifier));
	return			(result);
}
Esempio n. 7
0
void setGeometryIndices( Geometry * pGeom, const luabind::object & indexTable )
{
	if ( indexTable.is_valid() && indexTable.type() == LUA_TTABLE )
	{
		if ( !pGeom->m_indexBuffer ) pGeom->m_indexBuffer.reset( new vector<unsigned short> );
		unsigned int uiNewIndices = 0;
		pGeom->m_indexBuffer->clear();
		for( luabind::object::array_iterator iter = indexTable.abegin();
			iter != indexTable.aend();
			iter++, uiNewIndices++ )
		{
			boost::optional<unsigned short> oindex = luabind::object_cast_nothrow<unsigned short>( *iter );
			if ( oindex )
				pGeom->m_indexBuffer->push_back( *oindex.get() );
		}
		pGeom->m_indexCount = uiNewIndices;
	}
}
Esempio n. 8
0
void setGeometryTexture1( Geometry * pGeom, const luabind::object & texture1Table )
{
	if ( texture1Table.is_valid() && texture1Table.type() == LUA_TTABLE )
	{
		if ( !pGeom->m_texture1Buffer ) pGeom->m_texture1Buffer.reset( new vector<float> );
		pGeom->m_texture1Buffer->clear();
		for( luabind::object::array_iterator iter = texture1Table.abegin();
			iter != texture1Table.aend();
			iter++ )
		{
			boost::optional<Point2> opt = luabind::object_cast_nothrow<Point2>( *iter );
			if ( opt )
			{
				Point2 * pt = opt.get();
				pGeom->m_texture1Buffer->push_back( pt->x );
				pGeom->m_texture1Buffer->push_back( pt->y );
			}
		}
	}
}
Esempio n. 9
0
void setGeometryColor( Geometry * pGeom, const luabind::object & colorTable )
{
	if ( colorTable.is_valid() && colorTable.type() == LUA_TTABLE )
	{
		if ( !pGeom->m_colorBuffer ) pGeom->m_colorBuffer.reset( new vector<float> );
		pGeom->m_colorBuffer->clear();
		for( luabind::object::array_iterator iter = colorTable.abegin();
			iter != colorTable.aend();
			iter++ )
		{
			boost::optional<ColorA> opt = luabind::object_cast_nothrow<ColorA>( *iter );
			if ( opt )
			{
				ColorA * pt = opt.get();
				pGeom->m_colorBuffer->push_back( pt->r );
				pGeom->m_colorBuffer->push_back( pt->g );
				pGeom->m_colorBuffer->push_back( pt->b );
				pGeom->m_colorBuffer->push_back( pt->a );
			}
		}
	}
}
Esempio n. 10
0
//
// Local Functions
//
void setGeometryVertices( Geometry * pGeom, const luabind::object & vertexTable )
{
	if ( vertexTable.is_valid() && vertexTable.type() == LUA_TTABLE )
	{
		if ( !pGeom->m_vertexBuffer ) pGeom->m_vertexBuffer.reset( new vector<float> );
		pGeom->m_vertexBuffer->clear();
		unsigned uiNewVertices = 0;
		for( luabind::object::array_iterator iter = vertexTable.abegin();
			iter != vertexTable.aend();
			iter++, uiNewVertices++ )
		{
			boost::optional<Point3> opt = luabind::object_cast_nothrow<Point3>( *iter );
			if ( opt )
			{
				Point3 * pt = opt.get();
				pGeom->m_vertexBuffer->push_back( pt->x );
				pGeom->m_vertexBuffer->push_back( pt->y );
				pGeom->m_vertexBuffer->push_back( pt->z );
			}
		}
		pGeom->m_vertexCount = uiNewVertices;
	}
}