1 #ifndef AWFUL_LUA_TYPECHECK_H
2 #define AWFUL_LUA_TYPECHECK_H
4 namespace awful
{ namespace LuaImpl
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_
)
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_
);
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
69 template< typename T
> char type_tag
< T
>::dummy
;