//------------------------------------------------------------------------------
/*
https://github.com/vinniefalco/LuaBridge
-
+
+ Copyright 2016, Robin Gareus <robin@gareus.org>
Copyright 2012, Vinnie Falco <vinnie.falco@gmail.com>
License: The MIT License (http://www.opensource.org/licenses/mit-license.php)
/**
Get an untyped pointer to the contained class.
*/
- inline void* const getPointer ()
+ inline void* getPointer () const
{
return m_p;
}
either be of the intrusive variety, or in the style of the RefCountedPtr
type provided by LuaBridge (that uses a global hash table).
*/
-template <class C, bool byContainer>
+template <class C, bool byContainer, bool isEnum>
struct StackHelper
{
static inline void push (lua_State* L, C const& c)
retrieved may result in undefined behavior if Lua garbage collected it.
*/
template <class T>
-struct StackHelper <T, false>
+struct StackHelper <T, false, false>
{
static inline void push (lua_State* L, T const& t)
{
}
};
+template <class T>
+struct StackHelper <T, false, true>
+{
+ static inline void push (lua_State* L, T const& t)
+ {
+ int v = static_cast <int> (t);
+ lua_pushinteger (L, static_cast <lua_Integer> (v));
+ }
+
+ static inline T get (lua_State* L, int index)
+ {
+ int v = static_cast <int> (luaL_checkinteger (L, index));
+ return T (v);
+ }
+};
+
//==============================================================================
/**
static inline void push (lua_State* L, T const& t)
{
StackHelper <T,
- TypeTraits::isContainer <T>::value>::push (L, t);
+ TypeTraits::isContainer <T>::value,
+ TypeTraits::isEnum<T>::value>::push (L, t);
}
static inline T get (lua_State* L, int index)
{
return StackHelper <T,
- TypeTraits::isContainer <T>::value>::get (L, index);
+ TypeTraits::isContainer <T>::value,
+ TypeTraits::isEnum<T>::value>::get (L, index);
}
};
UserdataPtr::push (L, p);
}
- static inline T* const get (lua_State* L, int index)
+ static inline T* get (lua_State* L, int index)
{
return Userdata::get <T> (L, index, false);
}
UserdataPtr::push (L, p);
}
- static inline T* const get (lua_State* L, int index)
+ static inline T* get (lua_State* L, int index)
{
return Userdata::get <T> (L, index, false);
}
UserdataPtr::push (L, p);
}
- static inline T const* const get (lua_State* L, int index)
+ static inline T const* get (lua_State* L, int index)
{
return Userdata::get <T> (L, index, true);
}
UserdataPtr::push (L, p);
}
- static inline T const* const get (lua_State* L, int index)
+ static inline T const* get (lua_State* L, int index)
{
return Userdata::get <T> (L, index, true);
}
template <class C, bool byContainer>
struct RefStackHelper
{
- typedef C return_type;
-
+ typedef C return_type;
+
static inline void push (lua_State* L, C const& t)
{
UserdataSharedHelper <C,
template <class T>
struct RefStackHelper <T, false>
{
- typedef T const& return_type;
-
- static inline void push (lua_State* L, T const& t)
- {
- UserdataPtr::push (L, &t);
- }
+ typedef T const& return_type;
+
+ static inline void push (lua_State* L, T const& t)
+ {
+ UserdataPtr::push (L, &t);
+ }
static return_type get (lua_State* L, int index)
{