|
@@ -16,31 +16,6 @@
|
|
|
|
|
|
|
|
LUWRA_NS_BEGIN
|
|
LUWRA_NS_BEGIN
|
|
|
|
|
|
|
|
-namespace internal {
|
|
|
|
|
- template <typename T, typename... A>
|
|
|
|
|
- int userdata_ctor(State* state) {
|
|
|
|
|
- return apply(state, [state](A... args) {
|
|
|
|
|
- return Value<T>::push(state, args...);
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- template <typename T>
|
|
|
|
|
- int userdata_dtor(State* state) {
|
|
|
|
|
- Value<T*>::read(state, 1)->~T();
|
|
|
|
|
- return 0;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- template <typename T>
|
|
|
|
|
- int userdata_tostring(State* state) {
|
|
|
|
|
- T* instance = Value<T*>::read(state, 1);
|
|
|
|
|
-
|
|
|
|
|
- return Value<std::string>::push(
|
|
|
|
|
- state,
|
|
|
|
|
- std::string(T::MetatableName) + ": #" + std::to_string(uintmax_t(instance))
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* Instances of userdata shall always be used as pointers, because other Lua types can not be
|
|
* Instances of userdata shall always be used as pointers, because other Lua types can not be
|
|
|
* converted to pointers, hence this allows the compiler to differentiate between them.
|
|
* converted to pointers, hence this allows the compiler to differentiate between them.
|
|
@@ -74,6 +49,31 @@ struct Value<T*> {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+namespace internal {
|
|
|
|
|
+ template <typename T, typename... A>
|
|
|
|
|
+ int userdata_ctor(State* state) {
|
|
|
|
|
+ return apply(state, std::function<int(A...)>([state](A... args) {
|
|
|
|
|
+ return Value<T*>::push(state, args...);
|
|
|
|
|
+ }));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ template <typename T>
|
|
|
|
|
+ int userdata_dtor(State* state) {
|
|
|
|
|
+ Value<T*>::read(state, 1)->~T();
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ template <typename T>
|
|
|
|
|
+ int userdata_tostring(State* state) {
|
|
|
|
|
+ T* instance = Value<T*>::read(state, 1);
|
|
|
|
|
+
|
|
|
|
|
+ return Value<std::string>::push(
|
|
|
|
|
+ state,
|
|
|
|
|
+ std::string(T::MetatableName) + ": #" + std::to_string(uintmax_t(instance))
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Generate the metatable for the userdata type `T`. This function allows you to register methods
|
|
* Generate the metatable for the userdata type `T`. This function allows you to register methods
|
|
|
* which are shared across all instances of this type. A garbage-collector hook is also inserted;
|
|
* which are shared across all instances of this type. A garbage-collector hook is also inserted;
|