mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Merge pull request #225 from OrfeasZ/ut-helpers
Added helper functions for defining simple_usertype members manually.
This commit is contained in:
commit
68a9877a5e
|
@ -362,6 +362,21 @@ namespace sol {
|
|||
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)...);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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>> {
|
||||
|
|
Loading…
Reference in New Issue
Block a user