Merge branch 'master' into vulkan
Former-commit-id: fd9f2f119e959847d4d9eabece7b678243b26bde
This commit is contained in:
@@ -79,7 +79,8 @@ namespace Nz
|
||||
|
||||
OpenMode_Append = 0x01, // Disable writing on existing parts and put the cursor at the end
|
||||
OpenMode_Lock = 0x02, // Disable modifying the file before it is open
|
||||
OpenMode_ReadOnly = 0x04, // Open in read only
|
||||
OpenMode_MustExit = 0x04, // Fail if the file doesn't exists, even if opened in write mode
|
||||
OpenMode_ReadOnly = 0x08, // Open in read only
|
||||
OpenMode_Text = 0x10, // Open in text mod
|
||||
OpenMode_Truncate = 0x20, // Create the file if it doesn't exist and empty it if it exists
|
||||
OpenMode_WriteOnly = 0x40, // Open in write only, create the file if it doesn't exist
|
||||
@@ -105,7 +106,8 @@ namespace Nz
|
||||
enum Plugin
|
||||
{
|
||||
Plugin_Assimp,
|
||||
Plugin_FreeType
|
||||
|
||||
Plugin_Count
|
||||
};
|
||||
|
||||
enum PrimitiveType
|
||||
|
||||
@@ -65,6 +65,7 @@ namespace Nz
|
||||
bool SetCursorPos(CursorPosition pos, Int64 offset = 0);
|
||||
bool SetCursorPos(UInt64 offset) override;
|
||||
bool SetFile(const String& filePath);
|
||||
bool SetSize(UInt64 size);
|
||||
|
||||
File& operator=(const String& filePath);
|
||||
File& operator=(const File&) = delete;
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Nz
|
||||
void* OperatorNew(std::size_t size);
|
||||
|
||||
template<typename T, typename... Args>
|
||||
T* PlacementNew(void* ptr, Args&&... args);
|
||||
T* PlacementNew(T* ptr, Args&&... args);
|
||||
}
|
||||
|
||||
#include <Nazara/Core/MemoryHelper.inl>
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Nz
|
||||
* \param args Arguments for the constructor
|
||||
*/
|
||||
template<typename T, typename... Args>
|
||||
T* PlacementNew(void* ptr, Args&&... args)
|
||||
T* PlacementNew(T* ptr, Args&&... args)
|
||||
{
|
||||
return new (ptr) T(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ namespace Nz
|
||||
inline T* MemoryPool::New(Args&&... args)
|
||||
{
|
||||
T* object = static_cast<T*>(Allocate(sizeof(T)));
|
||||
PlacementNew<T>(object, std::forward<Args>(args)...);
|
||||
PlacementNew(object, std::forward<Args>(args)...);
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Nz
|
||||
public:
|
||||
using ClassFunc = std::function<int(LuaInstance& lua, T& instance)>;
|
||||
using ClassIndexFunc = std::function<bool(LuaInstance& lua, T& instance)>;
|
||||
using ConstructorFunc = std::function<T*(LuaInstance& lua)>;
|
||||
using ConstructorFunc = std::function<bool(LuaInstance& lua, T* instance)>;
|
||||
template<typename P> using ConvertToParent = std::function<P*(T*)>;
|
||||
using FinalizerFunc = std::function<bool(LuaInstance& lua, T& instance)>;
|
||||
using StaticIndexFunc = std::function<bool(LuaInstance& lua)>;
|
||||
@@ -36,6 +36,8 @@ namespace Nz
|
||||
|
||||
LuaClass(const String& name);
|
||||
|
||||
void BindDefaultConstructor();
|
||||
|
||||
void BindMethod(const String& name, ClassFunc method);
|
||||
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, T>::value> BindMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs);
|
||||
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, T>::value> BindMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs);
|
||||
|
||||
@@ -16,6 +16,16 @@ namespace Nz
|
||||
m_info->name = name;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void LuaClass<T>::BindDefaultConstructor()
|
||||
{
|
||||
SetConstructor([] (Nz::LuaInstance& lua, T* instance)
|
||||
{
|
||||
PlacementNew(instance);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template<class P>
|
||||
inline void LuaClass<T>::Inherit(LuaClass<P>& parent)
|
||||
@@ -36,7 +46,7 @@ namespace Nz
|
||||
|
||||
parentInfo->instanceGetters[m_info->name] = [info = m_info, convertFunc] (LuaInstance& lua) -> P*
|
||||
{
|
||||
return convertFunc(*static_cast<T**>(lua.CheckUserdata(1, info->name)));
|
||||
return convertFunc(static_cast<T*>(lua.CheckUserdata(1, info->name)));
|
||||
};
|
||||
|
||||
m_info->parentGetters.emplace_back([parentInfo, convertFunc] (LuaInstance& lua, T* instance)
|
||||
@@ -54,8 +64,8 @@ namespace Nz
|
||||
// cette UserData disposera d'un finalizer qui libérera le ClassInfo
|
||||
// Ainsi c'est Lua qui va s'occuper de la destruction pour nous :-)
|
||||
// De même, l'utilisation d'un shared_ptr permet de garder la structure en vie même si l'instance est libérée avant le LuaClass
|
||||
void* info = lua.PushUserdata(sizeof(std::shared_ptr<ClassInfo>));
|
||||
PlacementNew<std::shared_ptr<ClassInfo>>(info, m_info);
|
||||
std::shared_ptr<ClassInfo>* info = static_cast<std::shared_ptr<ClassInfo>*>(lua.PushUserdata(sizeof(std::shared_ptr<ClassInfo>)));
|
||||
PlacementNew(info, m_info);
|
||||
|
||||
// On créé la table qui contiendra une méthode (Le finalizer) pour libérer le ClassInfo
|
||||
lua.PushTable(0, 1);
|
||||
@@ -124,7 +134,7 @@ namespace Nz
|
||||
|
||||
m_info->instanceGetters[m_info->name] = [info = m_info] (LuaInstance& lua)
|
||||
{
|
||||
return *static_cast<T**>(lua.CheckUserdata(1, info->name));
|
||||
return static_cast<T*>(lua.CheckUserdata(1, info->name));
|
||||
};
|
||||
}
|
||||
lua.Pop(); // On pop la metatable
|
||||
@@ -322,14 +332,15 @@ namespace Nz
|
||||
|
||||
lua.Remove(1); // On enlève l'argument "table" du stack
|
||||
|
||||
T* instance = constructor(lua);
|
||||
if (!instance)
|
||||
T* instance = static_cast<T*>(lua.PushUserdata(sizeof(T)));
|
||||
|
||||
if (!constructor(lua, instance))
|
||||
{
|
||||
lua.Error("Constructor failed");
|
||||
return 0; // Normalement jamais exécuté (l'erreur provoquant une exception)
|
||||
}
|
||||
|
||||
lua.PushInstance(info->name.GetConstBuffer(), instance);
|
||||
lua.SetMetatable(info->name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -341,11 +352,11 @@ namespace Nz
|
||||
std::shared_ptr<ClassInfo>& info = *static_cast<std::shared_ptr<ClassInfo>*>(lua.ToUserdata(lua.GetIndexOfUpValue(1)));
|
||||
const FinalizerFunc& finalizer = info->finalizer;
|
||||
|
||||
T* instance = *static_cast<T**>(lua.CheckUserdata(1, info->name));
|
||||
T* instance = static_cast<T*>(lua.CheckUserdata(1, info->name));
|
||||
lua.Remove(1); //< Remove the instance from the Lua stack
|
||||
|
||||
if (!finalizer || finalizer(lua, *instance))
|
||||
delete instance;
|
||||
instance->~T();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -399,7 +410,7 @@ namespace Nz
|
||||
|
||||
std::shared_ptr<ClassInfo>& info = *static_cast<std::shared_ptr<ClassInfo>*>(lua.ToUserdata(lua.GetIndexOfUpValue(1)));
|
||||
|
||||
T* instance = *static_cast<T**>(lua.CheckUserdata(1, info->name));
|
||||
T* instance = static_cast<T*>(lua.CheckUserdata(1, info->name));
|
||||
lua.Remove(1); //< Remove the instance from the Lua stack
|
||||
|
||||
Get(info, lua, instance);
|
||||
@@ -448,7 +459,7 @@ namespace Nz
|
||||
std::shared_ptr<ClassInfo>& info = *static_cast<std::shared_ptr<ClassInfo>*>(lua.ToUserdata(lua.GetIndexOfUpValue(1)));
|
||||
const ClassIndexFunc& setter = info->setter;
|
||||
|
||||
T& instance = *(*static_cast<T**>(lua.CheckUserdata(1, info->name)));
|
||||
T& instance = *static_cast<T*>(lua.CheckUserdata(1, info->name));
|
||||
lua.Remove(1); //< Remove the instance from the Lua stack
|
||||
|
||||
if (!setter(lua, instance))
|
||||
|
||||
@@ -131,7 +131,8 @@ namespace Nz
|
||||
template<typename R, typename... Args, typename... DefArgs> void PushFunction(R(*func)(Args...), DefArgs&&... defArgs) const;
|
||||
template<typename T> void PushGlobal(const char* name, T&& arg);
|
||||
template<typename T> void PushGlobal(const String& name, T&& arg);
|
||||
template<typename T> void PushInstance(const char* tname, T* instance) const;
|
||||
template<typename T> void PushInstance(const char* tname, const T& instance) const;
|
||||
template<typename T> void PushInstance(const char* tname, T&& instance) const;
|
||||
template<typename T, typename... Args> void PushInstance(const char* tname, Args&&... args) const;
|
||||
void PushInteger(long long value) const;
|
||||
void PushLightUserdata(void* value) const;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <Nazara/Lua/LuaInstance.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/MemoryHelper.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
@@ -156,21 +157,21 @@ namespace Nz
|
||||
return LuaImplReplyVal(instance, val, TypeTag<T>());
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, std::string val, TypeTag<std::string>)
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, std::string&& val, TypeTag<std::string>)
|
||||
{
|
||||
instance.PushString(val.c_str(), val.size());
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, std::vector<T> valContainer, TypeTag<std::vector<T>>)
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, std::vector<T>&& valContainer, TypeTag<std::vector<T>>)
|
||||
{
|
||||
std::size_t index = 1;
|
||||
instance.PushTable(valContainer.size());
|
||||
for (const T& val : valContainer)
|
||||
for (T& val : valContainer)
|
||||
{
|
||||
instance.PushInteger(index++);
|
||||
if (LuaImplReplyVal(instance, val, TypeTag<T>()) != 1)
|
||||
if (LuaImplReplyVal(instance, std::move(val), TypeTag<T>()) != 1)
|
||||
{
|
||||
instance.Error("Couldn't create table: type need more than one place to store");
|
||||
return 0;
|
||||
@@ -181,20 +182,20 @@ namespace Nz
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, ByteArray val, TypeTag<ByteArray>)
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, ByteArray&& val, TypeTag<ByteArray>)
|
||||
{
|
||||
instance.PushString(reinterpret_cast<const char*>(val.GetConstBuffer()), val.GetSize());
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, String val, TypeTag<String>)
|
||||
inline int LuaImplReplyVal(const LuaInstance& instance, String&& val, TypeTag<String>)
|
||||
{
|
||||
instance.PushString(std::move(val));
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
int LuaImplReplyVal(const LuaInstance& instance, std::pair<T1, T2> val, TypeTag<std::pair<T1, T2>>)
|
||||
int LuaImplReplyVal(const LuaInstance& instance, std::pair<T1, T2>&& val, TypeTag<std::pair<T1, T2>>)
|
||||
{
|
||||
int retVal = 0;
|
||||
|
||||
@@ -593,24 +594,37 @@ namespace Nz
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void LuaInstance::PushInstance(const char* tname, T* instance) const
|
||||
void LuaInstance::PushInstance(const char* tname, const T& instance) const
|
||||
{
|
||||
T** userdata = static_cast<T**>(PushUserdata(sizeof(T*)));
|
||||
*userdata = instance;
|
||||
T* userdata = static_cast<T*>(PushUserdata(sizeof(T*)));
|
||||
PlacementNew(userdata, instance);
|
||||
|
||||
SetMetatable(tname);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void LuaInstance::PushInstance(const char* tname, T&& instance) const
|
||||
{
|
||||
T* userdata = static_cast<T*>(PushUserdata(sizeof(T*)));
|
||||
PlacementNew(userdata, std::move(instance));
|
||||
|
||||
SetMetatable(tname);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void LuaInstance::PushInstance(const char* tname, Args&&... args) const
|
||||
{
|
||||
PushInstance(tname, new T(std::forward<Args>(args)...));
|
||||
T* userdata = static_cast<T*>(PushUserdata(sizeof(T*)));
|
||||
PlacementNew(userdata, std::forward<Args>(args)...);
|
||||
|
||||
SetMetatable(tname);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T LuaInstance::CheckBounds(int index, long long value) const
|
||||
{
|
||||
long long minBounds = std::numeric_limits<T>::min();
|
||||
long long maxBounds = std::numeric_limits<T>::max();
|
||||
constexpr long long minBounds = std::numeric_limits<T>::min();
|
||||
constexpr long long maxBounds = std::numeric_limits<T>::max();
|
||||
if (value < minBounds || value > maxBounds)
|
||||
{
|
||||
Nz::StringStream stream;
|
||||
|
||||
Reference in New Issue
Block a user