Easier access to specific functions.

This commit is contained in:
ThePhD 2016-03-14 16:10:08 -04:00
parent a7405656af
commit 3de38f8da1
5 changed files with 44 additions and 3 deletions

View File

@ -530,7 +530,7 @@ struct pusher<unique_usertype<T, Real>> {
Real* mem = static_cast<Real*>(static_cast<void*>(fx + 1)); Real* mem = static_cast<Real*>(static_cast<void*>(fx + 1));
*fx = detail::special_destruct<T, Real>; *fx = detail::special_destruct<T, Real>;
detail::default_construct::construct(mem, std::forward<Args>(args)...); detail::default_construct::construct(mem, std::forward<Args>(args)...);
*pref = mem->get(); *pref = std::addressof(detail::deref(*mem));
if (luaL_newmetatable(L, &usertype_traits<unique_usertype<T>>::metatable[0]) == 1) { if (luaL_newmetatable(L, &usertype_traits<unique_usertype<T>>::metatable[0]) == 1) {
set_field(L, "__gc", detail::unique_destruct<T>); set_field(L, "__gc", detail::unique_destruct<T>);
} }
@ -539,13 +539,21 @@ struct pusher<unique_usertype<T, Real>> {
} }
}; };
template<typename T>
struct pusher<T, std::enable_if_t<is_unique_usertype<T>::value>> {
template <typename... Args>
static int push(lua_State* L, Args&&... args) {
typedef typename is_unique_usertype<T>::metatable_type meta_type;
return stack::push<unique_usertype<meta_type, T>>(L, std::forward<Args>(args)...);
}
};
template<typename T, typename D> template<typename T, typename D>
struct pusher<std::unique_ptr<T, D>> { struct pusher<std::unique_ptr<T, D>> {
static int push(lua_State* L, std::unique_ptr<T, D> obj) { static int push(lua_State* L, std::unique_ptr<T, D> obj) {
typedef std::unique_ptr<T, D> ptr_t;
if (obj == nullptr) if (obj == nullptr)
return stack::push(L, nil); return stack::push(L, nil);
return stack::push<unique_usertype<T, ptr_t>>(L, std::move(obj)); return stack::push<unique_usertype<T, std::unique_ptr<T, D>>>(L, std::move(obj));
} }
}; };

View File

@ -273,6 +273,15 @@ public:
return *this; return *this;
} }
table create_table(int narr = 0, int nrec = 0) {
return create_table(lua_state(), narr, nrec);
}
template <typename Key, typename Value, typename... Args>
table create_table(int narr, int nrec, Key&& key, Value&& value, Args&&... args) {
return create_table(lua_state(), narr, nrec, std::forward<Key>(key), std::forward<Value>(value), std::forward<Args>(args)...);
}
static inline table create_table(lua_State* L, int narr = 0, int nrec = 0) { static inline table create_table(lua_State* L, int narr = 0, int nrec = 0) {
return global_table::create(L, narr, nrec); return global_table::create(L, narr, nrec);
} }
@ -281,6 +290,14 @@ public:
static inline table create_table(lua_State* L, int narr, int nrec, Key&& key, Value&& value, Args&&... args) { static inline table create_table(lua_State* L, int narr, int nrec, Key&& key, Value&& value, Args&&... args) {
return global_table::create(L, narr, nrec, std::forward<Key>(key), std::forward<Value>(value), std::forward<Args>(args)...); return global_table::create(L, narr, nrec, std::forward<Key>(key), std::forward<Value>(value), std::forward<Args>(args)...);
} }
thread create_thread() {
return create_thread(lua_state());
}
static inline thread create_thread(lua_State* L, int narr = 0, int nrec = 0) {
return thread::create(L);
}
}; };
} // sol } // sol

View File

@ -271,6 +271,15 @@ private:
} }
public: public:
table create(int narr = 0, int nrec = 0) {
return create(lua_state(), narr, nrec);
}
template <typename Key, typename Value, typename... Args>
table create(int narr, int nrec, Key&& key, Value&& value, Args&&... args) {
return create(lua_state(), narr, nrec, std::forward<Key>(key), std::forward<Value>(value), std::forward<Args>(args)...);
}
static inline table create(lua_State* L, int narr = 0, int nrec = 0) { static inline table create(lua_State* L, int narr = 0, int nrec = 0) {
lua_createtable(L, narr, nrec); lua_createtable(L, narr, nrec);
table result(L); table result(L);

View File

@ -50,6 +50,10 @@ public:
return lstat; return lstat;
} }
thread create () {
return create(lua_state());
}
static thread create (lua_State* L) { static thread create (lua_State* L) {
lua_newthread(L); lua_newthread(L);
thread result(L); thread result(L);

View File

@ -286,6 +286,9 @@ struct is_proxy_primitive<std::reference_wrapper<T>> : std::true_type { };
template <typename... Args> template <typename... Args>
struct is_proxy_primitive<std::tuple<Args...>> : std::true_type { }; struct is_proxy_primitive<std::tuple<Args...>> : std::true_type { };
template <typename T>
struct is_unique_usertype : std::false_type {};
template<typename T> template<typename T>
inline type type_of() { inline type type_of() {
return lua_type_of<meta::Unqualified<T>>::value; return lua_type_of<meta::Unqualified<T>>::value;