Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
ThePhD 2016-09-17 12:03:43 -04:00
commit 8028628868
3 changed files with 53 additions and 4 deletions

View File

@ -355,13 +355,28 @@ namespace sol {
global.new_simple_usertype<Class, CTor0, CTor...>(name, std::forward<Args>(args)...);
return *this;
}
template<typename Class, typename... CArgs, typename... Args>
state_view& new_simple_usertype(const std::string& name, constructors<CArgs...> ctor, Args&&... args) {
global.new_simple_usertype<Class>(name, ctor, std::forward<Args>(args)...);
return *this;
}
template<typename Class, typename... Args>
simple_usertype<Class> create_simple_usertype(Args&&... args) {
return global.create_simple_usertype<Class>(std::forward<Args>(args)...);
}
template<typename Class, typename CTor0, typename... CTor, typename... Args>
simple_usertype<Class> create_simple_usertype(Args&&... args) {
return global.create_simple_usertype<Class, CTor0, CTor...>(std::forward<Args>(args)...);
}
template<typename Class, typename... CArgs, typename... Args>
simple_usertype<Class> create_simple_usertype(constructors<CArgs...> ctor, Args&&... args) {
return global.create_simple_usertype<Class>(ctor, std::forward<Args>(args)...);
}
template<bool read_only = true, typename... Args>
state_view& new_enum(const std::string& name, Args&&... args) {
global.new_enum<read_only>(name, std::forward<Args>(args)...);

View File

@ -274,7 +274,7 @@ namespace sol {
template<typename Class, typename... Args>
basic_table_core& new_simple_usertype(const std::string& name, Args&&... args) {
usertype<Class> utype(simple, base_t::lua_state(), std::forward<Args>(args)...);
simple_usertype<Class> utype(base_t::lua_state(), std::forward<Args>(args)...);
set_usertype(name, utype);
return *this;
}
@ -287,11 +287,29 @@ namespace sol {
template<typename Class, typename... CArgs, typename... Args>
basic_table_core& new_simple_usertype(const std::string& name, constructors<CArgs...> ctor, Args&&... args) {
usertype<Class> utype(simple, base_t::lua_state(), ctor, std::forward<Args>(args)...);
simple_usertype<Class> utype(base_t::lua_state(), ctor, std::forward<Args>(args)...);
set_usertype(name, utype);
return *this;
}
template<typename Class, typename... Args>
simple_usertype<Class> create_simple_usertype(Args&&... args) {
simple_usertype<Class> utype(base_t::lua_state(), std::forward<Args>(args)...);
return utype;
}
template<typename Class, typename CTor0, typename... CTor, typename... Args>
simple_usertype<Class> create_simple_usertype(Args&&... args) {
constructors<types<CTor0, CTor...>> ctor{};
return create_simple_usertype<Class>(ctor, std::forward<Args>(args)...);
}
template<typename Class, typename... CArgs, typename... Args>
simple_usertype<Class> create_simple_usertype(constructors<CArgs...> ctor, Args&&... args) {
simple_usertype<Class> utype(base_t::lua_state(), ctor, std::forward<Args>(args)...);
return utype;
}
template<bool read_only = true, typename... Args>
basic_table_core& new_enum(const std::string& name, Args&&... args) {
if (read_only) {

View File

@ -32,7 +32,7 @@ namespace sol {
template<typename T>
class usertype {
private:
protected:
std::unique_ptr<usertype_detail::registrar, detail::deleter> metatableregister;
template<typename... Args>
@ -63,6 +63,22 @@ namespace sol {
}
};
template<typename T>
class simple_usertype : public usertype<T> {
protected:
lua_State* state;
public:
template<typename... Args>
simple_usertype(lua_State* L, Args&&... args) : state(L), usertype(simple, L, std::forward<Args>(args)...) {}
template <typename N, typename F>
void add(N&& n, F&& f) {
auto meta = (simple_usertype_metatable<T>*) metatableregister.get();
meta->add(state, n, f);
}
};
namespace stack {
template<typename T>
struct pusher<usertype<T>> {