1 #ifndef AWFUL_LUA_BASIC_TYPES_H
2 #define AWFUL_LUA_BASIC_TYPES_H
4 namespace awful
{ namespace LuaImpl
6 template< typename category
, typename T
> struct TypeConverter
10 template< typename T
> struct NumericTypeConverter
12 NumericTypeConverter( lua_State
* pLS_
) :
17 bool CheckType_nothrow( int Index_
)
19 return LuaImpl::CheckType_nothrow( m_pLS
, Index_
, LUA_TNUMBER
);
22 void ConvertFromLua_nocheck( int Index_
, T
& Dest_
)
24 Dest_
= static_cast< T
>( lua_tonumber( m_pLS
, Index_
) );
27 void ConvertFromLua( int Index_
, T
& Dest_
)
29 CheckType( m_pLS
, Index_
, LUA_TNUMBER
);
30 ConvertFromLua_nocheck( Index_
, Dest_
);
33 void ConvertToLua( const T
& Value_
)
35 lua_pushnumber( m_pLS
, static_cast< lua_Number
>( Value_
) );
41 template<> struct TypeConverter
< NormalType
, int32_t > : NumericTypeConverter
< int32_t >
43 TypeConverter( lua_State
* pLS_
) : NumericTypeConverter
< int32_t >( pLS_
) {}
47 template<> struct TypeConverter
< NormalType
, uint32_t > : NumericTypeConverter
< uint32_t >
49 TypeConverter( lua_State
* pLS_
) : NumericTypeConverter
< uint32_t >( pLS_
) {}
53 template<> struct TypeConverter
< NormalType
, float > : NumericTypeConverter
< float >
55 TypeConverter( lua_State
* pLS_
) : NumericTypeConverter
< float >( pLS_
) {}
59 template<> struct TypeConverter
< NormalType
, bool >
61 TypeConverter( lua_State
* pLS_
) :
66 bool CheckType_nothrow( int Index_
)
68 return LuaImpl::CheckType_nothrow( m_pLS
, Index_
, LUA_TBOOLEAN
);
71 void ConvertFromLua_nocheck( int Index_
, bool& Dest_
)
73 Dest_
= !!lua_toboolean( m_pLS
, Index_
);
76 void ConvertFromLua( int Index_
, bool& Dest_
)
78 CheckType( m_pLS
, Index_
, LUA_TBOOLEAN
);
79 ConvertFromLua_nocheck( Index_
, Dest_
);
82 void ConvertToLua( const bool& Value_
)
84 lua_pushboolean( m_pLS
, Value_
);
91 template<> struct TypeConverter
< NormalType
, std::string
>
93 TypeConverter( lua_State
* pLS_
) :
98 bool CheckType_nothrow( int Index_
)
100 return LuaImpl::CheckType_nothrow( m_pLS
, Index_
, LUA_TSTRING
);
103 void ConvertFromLua_nocheck( int Index_
, std::string
& Dest_
)
105 Dest_
= lua_tostring( m_pLS
, Index_
);
108 void ConvertFromLua( int Index_
, std::string
& Dest_
)
110 CheckType( m_pLS
, Index_
, LUA_TSTRING
);
111 ConvertFromLua_nocheck( Index_
, Dest_
);
114 void ConvertToLua( const std::string
& Value_
)
116 lua_pushstring( m_pLS
, Value_
.c_str() );
122 // TODO: all other types