[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Start of Lua rewrite in C++
- From: Colin <share-lua@...>
- Date: Wed, 24 Oct 2007 19:50:44 +0200
On Wed, Oct 24, 2007 at 12:38:59PM -0500, James Porter wrote:
> On 10/24/07, Colin <share-lua@think42.com> wrote:
> >
> > - Change Lua to satisfy the exception requirements I mentioned in another
> > mail:
> > - Report errors from Lua as exceptions
> > - Allow exceptions to safely "fly through" Lua
> > which would make integration in C++ projects a heck more easy (that is
> > C++
> > projects on the level of "Exceptional C++" and "Modern C++ Design").
>
> This can already be done by redefining LUAI_THROW and LUAI_TRY and making a
> lua_exception class. I needed this feature for a project of my own, and
> managed to patch it into Lua 5.1.2 pretty easily. I agree that compiling Lua
> as C++ isn't enough, but I don't think a rewrite is necessary. If you're
> interested, I could put together a patch file with my changes.
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;
};