lua-users home
lua-l archive

Re: Start of Lua rewrite in C++

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 10/24/07, Colin <share-lua@think42.com> wrote:
Your patch would be highly welcome, yes! I am curious how you manage "fly
through" of exceptions without some half-serious changes...

Thanks, Colin


PS: Just thinking about Lua in C++ makes me think of all strange things...

template< typename T > struct ttraits;

template<> struct ttraits< void > { static const uint8_t type = 0; }
template<> struct ttraits< bool > { static const uint8_t type = 1; }

class tvalue
{
public:
tvalue()
: m_type( ttraits< void >::type )
{ }

template< class T > T & get()
{
if ( m_type != ttraits< T >::type )
throw "type mismatch bla bla";
else if ( sizeof( T ) <= sizeof( m_data ) )
return * reinterpret_cast< T * >( m_data );
else
return * reinterpret_cast< T * >( m_pointer );
}

template< class T > void set_small( const T & t )
{
m_type = ttraits< T >::type;

BOOST_STATIC_ASSERT( sizeof( T ) <= sizeof( m_data ) );

new ( m_data ) T( t );
}

private:
union
{
void * m_pointer;
uint8_t m_data[ 2 * sizeof( void * ) - 1 ];
};
uint8_t m_type;
};

I use a C++ wrapper called Luaxx. It is a header only approach. I really like it. I have made additions to it. It had a few problems compiling on MinGW and VC, but I fixed them. I tried to contact the developer, but I got no response. I will post it when I get the compiling on Linux issues squared away

Here are the details for the original:
http://matt-land.com/luaxx/
--
Regards,
Ryan
RJP Computing

AltStyle によって変換されたページ (->オリジナル) /