All modules now compile again.
[fail.git] / include / services / bindings / lua / typecheck.h
blob80ac835c55a87d12c875821fdd4f4ba56306ea74
1 #ifndef AWFUL_LUA_TYPECHECK_H
2 #define AWFUL_LUA_TYPECHECK_H
4 namespace awful { namespace LuaImpl
6 enum e_CheckingPolicy
8 cp_NoCheck,
9 cp_NoThrow,
10 cp_Throw
13 template< e_CheckingPolicy CheckPolicy > struct TypeCheckHelpers
15 static void ThrowTypeMismatch( int Got_ = LUA_TNONE, int Expected_ = LUA_TNONE )
19 static bool CheckType( lua_State* pLS, int Index_, int ExpectedType_ )
21 return true;
25 template<> struct TypeCheckHelpers< cp_Throw >
27 static void ThrowTypeMismatch( int Got_ = LUA_TNONE, int Expected_ = LUA_TNONE )
29 throw Error::TypeMismatch( Got_, Expected_ );
32 static bool CheckType( lua_State* pLS, int Index_, int ExpectedType_ )
34 int type = lua_type( pLS, Index_ );
35 if( type != ExpectedType_ )
36 throw Error::TypeMismatch( type, ExpectedType_ );
38 return true;
42 template<> struct TypeCheckHelpers< cp_NoThrow >
44 static void ThrowTypeMismatch( int Got_ = LUA_TNONE, int Expected_ = LUA_TNONE )
48 static bool CheckType( lua_State* pLS, int Index_, int ExpectedType_ )
50 int type = lua_type( pLS, Index_ );
51 return type == ExpectedType_;
55 // The address of the dummy field of that class is unique
56 // for each class compiled in the executable.
57 // This provides a simple way to identify type, that can be embedded
58 // into a lua light user data to be used as keys in lua tables.
60 // This would not work portably with the address of std::type_info structures, because
61 // comparing type_info addresses is not portable (as with some systems/compiler/linkers
62 // you may end up with several instances of the same type_info in the final binary)
63 // and lua assumes that a light user data contains an address that it can directly
64 // hash when used as a table key.
65 template< typename T > struct type_tag
67 static char dummy;
69 template< typename T > char type_tag< T >::dummy;
72 #endif