Skip to content

Commit

Permalink
Enable binding of const primitives as variables
Browse files Browse the repository at this point in the history
  • Loading branch information
krisr committed Sep 15, 2014
1 parent 1a68cc8 commit 38423f4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
13 changes: 12 additions & 1 deletion LuaIntf/impl/CppBindClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ class CppBindClass : public CppBindClassBase
/**
* Add or replace a data member.
*/
template <typename V>
template <typename V, typename std::enable_if<!std::is_const<V>::value>::type* = nullptr>
CppBindClass<T>& addVariable(const char* name, V T::* v, bool writable = true)
{
setMemberGetter(name, LuaRef::createFunction(state(), &CppBindClassVariable<T, V>::get, v));
Expand All @@ -609,6 +609,17 @@ class CppBindClass : public CppBindClassBase
}
return *this;
}

/**
* Add or replace a data member.
*/
template <typename V, typename std::enable_if<std::is_const<V>::value>::type* = nullptr>
CppBindClass<T>& addVariable(const char* name, V T::* v)
{
setMemberGetter(name, LuaRef::createFunction(state(), &CppBindClassVariable<T, V>::get, v));
setMemberReadOnly(name);
return *this;
}

/**
* Add or replace a property member.
Expand Down
2 changes: 1 addition & 1 deletion LuaIntf/impl/CppBindModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class CppBindModule
}
return *this;
}

/**
* Add or replace a read-write property.
*/
Expand Down
3 changes: 2 additions & 1 deletion LuaIntf/impl/LuaType.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ struct LuaValueType <unsigned long long, lua_Number> : LuaUnsafeInt64Type <unsig
#define LUA_USING_VALUE_TYPE_EXT(T, V) \
template <> struct LuaType <T> : LuaValueType <T, V> {}; \
template <> struct LuaType <T&> : LuaValueType <T, V> {}; \
template <> struct LuaType <T const&> : LuaValueType <T, V> {};
template <> struct LuaType <T const&> : LuaValueType <T, V> {}; \
template <> struct LuaType <T const> : LuaValueType <T, V> {};

#define LUA_USING_VALUE_TYPE(T) \
LUA_USING_VALUE_TYPE_EXT(T, T)
Expand Down

0 comments on commit 38423f4

Please sign in to comment.