Lua: Some fixes

Former-commit-id: 6db68a9c5e29a81fdd590bd11167841dda780af1
This commit is contained in:
Lynix 2015-12-17 14:20:33 +01:00
parent 52599132a7
commit 163e73f5d2
3 changed files with 189 additions and 189 deletions

View File

@ -42,15 +42,15 @@ namespace Nz
bool Call(unsigned int argCount);
bool Call(unsigned int argCount, unsigned int resultCount);
template<typename T> T Check(unsigned int* index);
template<typename T> T Check(unsigned int* index, T defValue);
template<typename T> T Check(int* index) const;
template<typename T> T Check(int* index, T defValue) const;
void CheckAny(int index) const;
bool CheckBoolean(int index) const;
bool CheckBoolean(int index, bool defValue) const;
template<typename T> T CheckField(const char* fieldName, int tableIndex = -1);
template<typename T> T CheckField(const String& fieldName, int tableIndex = -1);
template<typename T> T CheckField(const char* fieldName, T defValue, int tableIndex = -1);
template<typename T> T CheckField(const String& fieldName, T defValue, int tableIndex = -1);
template<typename T> T CheckField(const char* fieldName, int tableIndex = -1) const;
template<typename T> T CheckField(const String& fieldName, int tableIndex = -1) const;
template<typename T> T CheckField(const char* fieldName, T defValue, int tableIndex = -1) const;
template<typename T> T CheckField(const String& fieldName, T defValue, int tableIndex = -1) const;
long long CheckInteger(int index) const;
long long CheckInteger(int index, long long defValue) const;
template<typename T> T CheckGlobal(const char* fieldName) const;
@ -68,17 +68,17 @@ namespace Nz
void* CheckUserdata(int index, const String& tname) const;
bool Compare(int index1, int index2, LuaComparison comparison) const;
void Compute(LuaOperation operation);
void Compute(LuaOperation operation) const;
void Concatenate(int count);
void Concatenate(int count) const;
int CreateReference();
void DestroyReference(int ref);
String DumpStack() const;
void Error(const char* message);
void Error(const String& message);
void Error(const char* message) const;
void Error(const String& message) const;
bool Execute(const String& code);
bool ExecuteFromFile(const String& filePath);
@ -103,7 +103,7 @@ namespace Nz
LuaType GetType(int index) const;
const char* GetTypeName(LuaType type) const;
void Insert(int index);
void Insert(int index) const;
bool IsOfType(int index, LuaType type) const;
bool IsOfType(int index, const char* tname) const;
@ -112,37 +112,37 @@ namespace Nz
long long Length(int index) const;
void MoveTo(LuaInstance* instance, int n);
void MoveTo(LuaInstance* instance, int n) const;
bool NewMetatable(const char* str);
bool NewMetatable(const String& str);
bool Next(int index = -2);
bool Next(int index = -2) const;
void Pop(unsigned int n = 1U);
void Pop(unsigned int n = 1U) const;
template<typename T> int Push(T arg);
void PushBoolean(bool value);
void PushCFunction(LuaCFunction func, unsigned int upvalueCount = 0);
void PushFunction(LuaFunction func);
template<typename R, typename... Args, typename... DefArgs> void PushFunction(R(*func)(Args...), DefArgs&&... defArgs);
template<typename T> void PushInstance(const char* tname, T* instance);
template<typename T, typename... Args> void PushInstance(const char* tname, Args&&... args);
void PushInteger(long long value);
void PushLightUserdata(void* value);
void PushMetatable(const char* str);
void PushMetatable(const String& str);
void PushNil();
void PushNumber(double value);
void PushReference(int ref);
void PushString(const char* str);
void PushString(const char* str, unsigned int size);
void PushString(const String& str);
void PushTable(unsigned int sequenceElementCount = 0, unsigned int arrayElementCount = 0);
void* PushUserdata(unsigned int size);
void PushValue(int index);
template<typename T> int Push(T arg) const;
void PushBoolean(bool value) const;
void PushCFunction(LuaCFunction func, unsigned int upvalueCount = 0) const;
void PushFunction(LuaFunction func) const;
template<typename R, typename... Args, typename... DefArgs> void PushFunction(R(*func)(Args...), DefArgs&&... defArgs) 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;
void PushMetatable(const char* str) const;
void PushMetatable(const String& str) const;
void PushNil() const;
void PushNumber(double value) const;
void PushReference(int ref) const;
void PushString(const char* str) const;
void PushString(const char* str, unsigned int size) const;
void PushString(const String& str) const;
void PushTable(unsigned int sequenceElementCount = 0, unsigned int arrayElementCount = 0) const;
void* PushUserdata(unsigned int size) const;
void PushValue(int index) const;
void Remove(int index);
void Replace(int index);
void Remove(int index) const;
void Replace(int index) const;
template<typename T> void SetField(const char* name, T&& arg, int tableIndex = -2);
template<typename T> void SetField(const String& name, T&& arg, int tableIndex = -2);
@ -152,9 +152,9 @@ namespace Nz
template<typename T> void SetGlobal(const String& name, T&& arg);
void SetGlobal(const char* name);
void SetGlobal(const String& name);
void SetMetatable(const char* tname);
void SetMetatable(const String& tname);
void SetMetatable(int index);
void SetMetatable(const char* tname) const;
void SetMetatable(const String& tname) const;
void SetMetatable(int index) const;
void SetMemoryLimit(UInt32 memoryLimit);
void SetTable(int index = -3);
void SetTimeLimit(UInt32 timeLimit);

View File

@ -9,80 +9,19 @@
namespace Nz
{
// Functions args
inline unsigned int LuaImplQueryArg(LuaInstance& instance, int index, bool* arg, TypeTag<bool>)
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, bool* arg, TypeTag<bool>)
{
*arg = instance.CheckBoolean(index);
return 1;
}
inline unsigned int LuaImplQueryArg(LuaInstance& instance, int index, bool* arg, bool defValue, TypeTag<bool>)
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, bool* arg, bool defValue, TypeTag<bool>)
{
*arg = instance.CheckBoolean(index, defValue);
return 1;
}
template<typename T>
std::enable_if_t<std::is_enum<T>::value, unsigned int> LuaImplQueryArg(LuaInstance& instance, int index, T* arg, TypeTag<T>)
{
using UnderlyingT = std::underlying_type_t<T>;
*arg = static_cast<T>(LuaImplQueryArg(instance, index, reinterpret_cast<UnderlyingT*>(arg), TypeTag<UnderlyingT>()));
return 1;
}
template<typename T>
std::enable_if_t<std::is_enum<T>::value, unsigned int> LuaImplQueryArg(LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
{
using UnderlyingT = std::underlying_type_t<T>;
*arg = static_cast<T>(LuaImplQueryArg(instance, index, reinterpret_cast<UnderlyingT*>(arg), static_cast<UnderlyingT>(defValue), TypeTag<UnderlyingT>()));
return 1;
}
template<typename T>
std::enable_if_t<std::is_floating_point<T>::value, unsigned int> LuaImplQueryArg(LuaInstance& instance, int index, T* arg, TypeTag<T>)
{
*arg = static_cast<T>(instance.CheckNumber(index));
return 1;
}
template<typename T>
std::enable_if_t<std::is_floating_point<T>::value, unsigned int> LuaImplQueryArg(LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
{
*arg = static_cast<T>(instance.CheckNumber(index, static_cast<double>(defValue)));
return 1;
}
template<typename T>
std::enable_if_t<std::is_integral<T>::value && !std::is_unsigned<T>::value, unsigned int> LuaImplQueryArg(LuaInstance& instance, int index, T* arg, TypeTag<T>)
{
*arg = static_cast<T>(instance.CheckInteger(index));
return 1;
}
template<typename T>
std::enable_if_t<std::is_integral<T>::value && !std::is_unsigned<T>::value, unsigned int> LuaImplQueryArg(LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
{
*arg = static_cast<T>(instance.CheckInteger(index, defValue));
return 1;
}
template<typename T>
std::enable_if_t<std::is_unsigned<T>::value, unsigned int> LuaImplQueryArg(LuaInstance& instance, int index, T* arg, TypeTag<T>)
{
using SignedT = std::make_signed_t<T>;
return LuaImplQueryArg(instance, index, reinterpret_cast<SignedT*>(arg), TypeTag<SignedT>());
}
template<typename T>
std::enable_if_t<std::is_unsigned<T>::value, unsigned int> LuaImplQueryArg(LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
{
using SignedT = std::make_signed_t<T>;
return LuaImplQueryArg(instance, index, reinterpret_cast<SignedT*>(arg), static_cast<SignedT>(defValue), TypeTag<SignedT>());
}
inline unsigned int LuaImplQueryArg(LuaInstance& instance, int index, std::string* arg, TypeTag<std::string>)
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, std::string* arg, TypeTag<std::string>)
{
std::size_t strLength = 0;
const char* str = instance.CheckString(index, &strLength);
@ -92,7 +31,7 @@ namespace Nz
return 1;
}
inline unsigned int LuaImplQueryArg(LuaInstance& instance, int index, String* arg, TypeTag<String>)
inline unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, String* arg, TypeTag<String>)
{
std::size_t strLength = 0;
const char* str = instance.CheckString(index, &strLength);
@ -103,7 +42,68 @@ namespace Nz
}
template<typename T>
unsigned int LuaImplQueryArg(LuaInstance& instance, int index, T* arg, const T& defValue, TypeTag<T> tag)
std::enable_if_t<std::is_enum<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
{
using UnderlyingT = std::underlying_type_t<T>;
*arg = static_cast<T>(LuaImplQueryArg(instance, index, reinterpret_cast<UnderlyingT*>(arg), TypeTag<UnderlyingT>()));
return 1;
}
template<typename T>
std::enable_if_t<std::is_enum<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
{
using UnderlyingT = std::underlying_type_t<T>;
*arg = static_cast<T>(LuaImplQueryArg(instance, index, reinterpret_cast<UnderlyingT*>(arg), static_cast<UnderlyingT>(defValue), TypeTag<UnderlyingT>()));
return 1;
}
template<typename T>
std::enable_if_t<std::is_floating_point<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
{
*arg = static_cast<T>(instance.CheckNumber(index));
return 1;
}
template<typename T>
std::enable_if_t<std::is_floating_point<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
{
*arg = static_cast<T>(instance.CheckNumber(index, static_cast<double>(defValue)));
return 1;
}
template<typename T>
std::enable_if_t<std::is_integral<T>::value && !std::is_unsigned<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
{
*arg = static_cast<T>(instance.CheckInteger(index));
return 1;
}
template<typename T>
std::enable_if_t<std::is_integral<T>::value && !std::is_unsigned<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
{
*arg = static_cast<T>(instance.CheckInteger(index, defValue));
return 1;
}
template<typename T>
std::enable_if_t<std::is_unsigned<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
{
using SignedT = std::make_signed_t<T>;
return LuaImplQueryArg(instance, index, reinterpret_cast<SignedT*>(arg), TypeTag<SignedT>());
}
template<typename T>
std::enable_if_t<std::is_unsigned<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
{
using SignedT = std::make_signed_t<T>;
return LuaImplQueryArg(instance, index, reinterpret_cast<SignedT*>(arg), static_cast<SignedT>(defValue), TypeTag<SignedT>());
}
template<typename T>
unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, const T& defValue, TypeTag<T> tag)
{
if (instance.IsValid(index))
return LuaImplQueryArg(instance, index, arg, tag);
@ -115,38 +115,38 @@ namespace Nz
}
template<typename T>
unsigned int LuaImplQueryArg(LuaInstance& instance, int index, T* arg, TypeTag<const T&>)
unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<const T&>)
{
return LuaImplQueryArg(instance, index, arg, TypeTag<T>());
}
template<typename T>
unsigned int LuaImplQueryArg(LuaInstance& instance, int index, T* arg, const T& defValue, TypeTag<const T&>)
unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, const T& defValue, TypeTag<const T&>)
{
return LuaImplQueryArg(instance, index, arg, defValue, TypeTag<T>());
}
// Function returns
inline int LuaImplReplyVal(LuaInstance& instance, bool val, TypeTag<bool>)
inline int LuaImplReplyVal(const LuaInstance& instance, bool val, TypeTag<bool>)
{
instance.PushBoolean(val);
return 1;
}
inline int LuaImplReplyVal(LuaInstance& instance, double val, TypeTag<double>)
inline int LuaImplReplyVal(const LuaInstance& instance, double val, TypeTag<double>)
{
instance.PushNumber(val);
return 1;
}
inline int LuaImplReplyVal(LuaInstance& instance, float val, TypeTag<float>)
inline int LuaImplReplyVal(const LuaInstance& instance, float val, TypeTag<float>)
{
instance.PushNumber(val);
return 1;
}
template<typename T>
std::enable_if_t<std::is_enum<T>::value, int> LuaImplReplyVal(LuaInstance& instance, T val, TypeTag<T>)
std::enable_if_t<std::is_enum<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
{
using EnumT = typename std::underlying_type<T>::type;
@ -154,34 +154,34 @@ namespace Nz
}
template<typename T>
std::enable_if_t<std::is_integral<T>::value && !std::is_unsigned<T>::value, int> LuaImplReplyVal(LuaInstance& instance, T val, TypeTag<T>)
std::enable_if_t<std::is_integral<T>::value && !std::is_unsigned<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
{
instance.PushInteger(val);
return 1;
}
template<typename T>
std::enable_if_t<std::is_unsigned<T>::value, int> LuaImplReplyVal(LuaInstance& instance, T val, TypeTag<T>)
std::enable_if_t<std::is_unsigned<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
{
using SignedT = typename std::make_signed<T>::type;
return LuaImplReplyVal(instance, static_cast<SignedT>(val), TypeTag<SignedT>());
}
inline int LuaImplReplyVal(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;
}
inline int LuaImplReplyVal(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(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;
@ -198,7 +198,7 @@ namespace Nz
struct LuaImplArgProcesser<true>
{
template<std::size_t N, std::size_t FirstDefArg, typename ArgType, typename ArgContainer, typename DefArgContainer>
static unsigned int Process(LuaInstance& instance, unsigned int argIndex, ArgContainer& args, DefArgContainer& defArgs)
static unsigned int Process(const LuaInstance& instance, unsigned int argIndex, ArgContainer& args, DefArgContainer& defArgs)
{
return LuaImplQueryArg(instance, argIndex, &std::get<N>(args), std::get<std::tuple_size<DefArgContainer>() - N + FirstDefArg - 1>(defArgs), TypeTag<ArgType>());
}
@ -208,7 +208,7 @@ namespace Nz
struct LuaImplArgProcesser<false>
{
template<std::size_t N, std::size_t FirstDefArg, typename ArgType, typename ArgContainer, typename DefArgContainer>
static unsigned int Process(LuaInstance& instance, unsigned int argIndex, ArgContainer& args, DefArgContainer& defArgs)
static unsigned int Process(const LuaInstance& instance, unsigned int argIndex, ArgContainer& args, DefArgContainer& defArgs)
{
NazaraUnused(defArgs);
@ -231,18 +231,18 @@ namespace Nz
static constexpr std::size_t FirstDefArg = ArgCount - DefArgCount;
public:
Impl(LuaInstance& instance, DefArgs... defArgs) :
Impl(DefArgs... defArgs) :
m_defaultArgs(std::forward<DefArgs>(defArgs)...)
{
}
void ProcessArgs(LuaInstance& instance) const
void ProcessArgs(const LuaInstance& instance) const
{
m_index = 1;
ProcessArgs<0, Args...>(instance);
}
int Invoke(LuaInstance& instance, void(*func)(Args...)) const
int Invoke(const LuaInstance& instance, void(*func)(Args...)) const
{
NazaraUnused(instance);
@ -251,7 +251,7 @@ namespace Nz
}
template<typename Ret>
int Invoke(LuaInstance& instance, Ret(*func)(Args...)) const
int Invoke(const LuaInstance& instance, Ret(*func)(Args...)) const
{
return LuaImplReplyVal(instance, std::move(Apply(func, m_args)), TypeTag<decltype(Apply(func, m_args))>());
}
@ -261,7 +261,7 @@ namespace Nz
using DefArgContainer = std::tuple<std::remove_cv_t<std::remove_reference_t<DefArgs>>...>;
template<std::size_t N>
void ProcessArgs(LuaInstance& instance) const
void ProcessArgs(const LuaInstance& instance) const
{
NazaraUnused(instance);
@ -269,13 +269,13 @@ namespace Nz
}
template<std::size_t N, typename ArgType>
void ProcessArgs(LuaInstance& instance) const
void ProcessArgs(const LuaInstance& instance) const
{
LuaImplArgProcesser<(N >= FirstDefArg)>::template Process<N, FirstDefArg, ArgType>(instance, &m_index, m_args, m_defaultArgs);
LuaImplArgProcesser<(N >= FirstDefArg)>::template Process<N, FirstDefArg, ArgType>(instance, m_index, m_args, m_defaultArgs);
}
template<std::size_t N, typename ArgType1, typename ArgType2, typename... Rest>
void ProcessArgs(LuaInstance& instance) const
void ProcessArgs(const LuaInstance& instance) const
{
ProcessArgs<N, ArgType1>(instance);
ProcessArgs<N + 1, ArgType2, Rest...>(instance);
@ -307,14 +307,14 @@ namespace Nz
{
}
void ProcessArgs(LuaInstance& instance) const
void ProcessArgs(const LuaInstance& instance) const
{
m_index = 1;
ProcessArgs<0, Args...>(instance);
}
template<typename T, typename P>
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(LuaInstance& instance, T& object, void(P::*func)(Args...)) const
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(const LuaInstance& instance, T& object, void(P::*func)(Args...)) const
{
NazaraUnused(instance);
@ -323,13 +323,13 @@ namespace Nz
}
template<typename T, typename P, typename Ret>
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(LuaInstance& instance, T& object, Ret(P::*func)(Args...)) const
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(const LuaInstance& instance, T& object, Ret(P::*func)(Args...)) const
{
return LuaImplReplyVal(instance, std::move(Apply(object, func, m_args)), TypeTag<decltype(Apply(object, func, m_args))>());
}
template<typename T, typename P>
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(LuaInstance& instance, const T& object, void(P::*func)(Args...) const) const
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(const LuaInstance& instance, const T& object, void(P::*func)(Args...) const) const
{
NazaraUnused(instance);
@ -338,13 +338,13 @@ namespace Nz
}
template<typename T, typename P, typename Ret>
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(LuaInstance& instance, const T& object, Ret(P::*func)(Args...) const) const
std::enable_if_t<std::is_base_of<P, T>::value, int> Invoke(const LuaInstance& instance, const T& object, Ret(P::*func)(Args...) const) const
{
return LuaImplReplyVal(instance, std::move(Apply(object, func, m_args)), TypeTag<decltype(Apply(object, func, m_args))>());
}
template<typename T, typename P>
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(LuaInstance& instance, T& object, void(P::*func)(Args...)) const
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaInstance& instance, T& object, void(P::*func)(Args...)) const
{
NazaraUnused(instance);
@ -353,13 +353,13 @@ namespace Nz
}
template<typename T, typename P, typename Ret>
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(LuaInstance& instance, T& object, Ret(P::*func)(Args...)) const
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaInstance& instance, T& object, Ret(P::*func)(Args...)) const
{
return LuaImplReplyVal(instance, std::move(Apply(*object, func, m_args)), TypeTag<decltype(Apply(*object, func, m_args))>());
}
template<typename T, typename P>
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(LuaInstance& instance, const T& object, void(P::*func)(Args...) const) const
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaInstance& instance, const T& object, void(P::*func)(Args...) const) const
{
NazaraUnused(instance);
@ -368,7 +368,7 @@ namespace Nz
}
template<typename T, typename P, typename Ret>
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(LuaInstance& instance, const T& object, Ret(P::*func)(Args...) const) const
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value, int> Invoke(const LuaInstance& instance, const T& object, Ret(P::*func)(Args...) const) const
{
return LuaImplReplyVal(instance, std::move(Apply(*object, func, m_args)), TypeTag<decltype(Apply(*object, func, m_args))>());
}
@ -378,7 +378,7 @@ namespace Nz
using DefArgContainer = std::tuple<std::remove_cv_t<std::remove_reference_t<DefArgs>>...>;
template<std::size_t N>
void ProcessArgs(LuaInstance& instance) const
void ProcessArgs(const LuaInstance& instance) const
{
NazaraUnused(instance);
@ -386,13 +386,13 @@ namespace Nz
}
template<std::size_t N, typename ArgType>
void ProcessArgs(LuaInstance& instance) const
void ProcessArgs(const LuaInstance& instance) const
{
m_index += LuaImplArgProcesser<(N >= FirstDefArg)>::template Process<N, FirstDefArg, ArgType>(instance, m_index, m_args, m_defaultArgs);
}
template<std::size_t N, typename ArgType1, typename ArgType2, typename... Rest>
void ProcessArgs(LuaInstance& instance) const
void ProcessArgs(const LuaInstance& instance) const
{
ProcessArgs<N, ArgType1>(instance);
ProcessArgs<N + 1, ArgType2, Rest...>(instance);
@ -405,29 +405,29 @@ namespace Nz
};
template<typename T>
T LuaInstance::Check(unsigned int* index)
T LuaInstance::Check(int* index) const
{
NazaraAssert(index, "Invalid index pointer");
T object;
*index += LuaImplQueryArg(*this, index, &object, TypeTag<T>());
*index += LuaImplQueryArg(*this, *index, &object, TypeTag<T>());
return object;
}
template<typename T>
T LuaInstance::Check(unsigned int* index, T defValue)
T LuaInstance::Check(int* index, T defValue) const
{
NazaraAssert(index, "Invalid index pointer");
T object;
*index += LuaImplQueryArg(*this, index, &object, defValue, TypeTag<T>());
*index += LuaImplQueryArg(*this, *index, &object, defValue, TypeTag<T>());
return object;
}
template<typename T>
T LuaInstance::CheckField(const char* fieldName, int tableIndex)
T LuaInstance::CheckField(const char* fieldName, int tableIndex) const
{
T object;
@ -439,13 +439,13 @@ namespace Nz
}
template<typename T>
T LuaInstance::CheckField(const String& fieldName, int tableIndex)
T LuaInstance::CheckField(const String& fieldName, int tableIndex) const
{
return CheckField(fieldName.GetConstBuffer(), tableIndex);
return CheckField<T>(fieldName.GetConstBuffer(), tableIndex);
}
template<typename T>
T LuaInstance::CheckField(const char* fieldName, T defValue, int tableIndex)
T LuaInstance::CheckField(const char* fieldName, T defValue, int tableIndex) const
{
T object;
@ -457,55 +457,55 @@ namespace Nz
}
template<typename T>
T LuaInstance::CheckField(const String& fieldName, T defValue, int tableIndex)
T LuaInstance::CheckField(const String& fieldName, T defValue, int tableIndex) const
{
return CheckField(fieldName.GetConstBuffer(), defValue, tableIndex);
return CheckField<T>(fieldName.GetConstBuffer(), defValue, tableIndex);
}
template<typename T>
T LuaInstance::CheckGlobal(const char* fieldName)
T LuaInstance::CheckGlobal(const char* fieldName) const
{
T object;
GetGlobal(fieldName);
tableIndex += LuaImplQueryArg(*this, -1, &object, TypeTag<T>());
LuaImplQueryArg(*this, -1, &object, TypeTag<T>());
Pop();
return object;
}
template<typename T>
T LuaInstance::CheckGlobal(const String& fieldName)
T LuaInstance::CheckGlobal(const String& fieldName) const
{
return CheckGlobal(fieldName.GetConstBuffer());
return CheckGlobal<T>(fieldName.GetConstBuffer());
}
template<typename T>
T LuaInstance::CheckGlobal(const char* fieldName, T defValue)
T LuaInstance::CheckGlobal(const char* fieldName, T defValue) const
{
T object;
GetGlobal(fieldName);
tableIndex += LuaImplQueryArg(*this, -1, &object, defValue, TypeTag<T>());
LuaImplQueryArg(*this, -1, &object, defValue, TypeTag<T>());
Pop();
return object;
}
template<typename T>
T LuaInstance::CheckGlobal(const String& fieldName, T defValue)
T LuaInstance::CheckGlobal(const String& fieldName, T defValue) const
{
return CheckGlobal(fieldName.GetConstBuffer(), defValue);
return CheckGlobal<T>(fieldName.GetConstBuffer(), defValue);
}
template<typename T>
int LuaInstance::Push(T arg)
int LuaInstance::Push(T arg) const
{
return LuaImplReplyVal(*this, std::move(arg), TypeTag<T>());
}
template<typename R, typename... Args, typename... DefArgs>
void LuaInstance::PushFunction(R(*func)(Args...), DefArgs&&... defArgs)
void LuaInstance::PushFunction(R(*func)(Args...), DefArgs&&... defArgs) const
{
typename LuaImplFunctionProxy<Args...>::template Impl<DefArgs...> handler(std::forward<DefArgs>(defArgs)...);
@ -518,7 +518,7 @@ namespace Nz
}
template<typename T>
void LuaInstance::PushInstance(const char* tname, T* instance)
void LuaInstance::PushInstance(const char* tname, T* instance) const
{
T** userdata = static_cast<T**>(PushUserdata(sizeof(T*)));
*userdata = instance;
@ -526,7 +526,7 @@ namespace Nz
}
template<typename T, typename... Args>
void LuaInstance::PushInstance(const char* tname, Args&&... args)
void LuaInstance::PushInstance(const char* tname, Args&&... args) const
{
PushInstance(tname, new T(std::forward<Args>(args)...));
}

View File

@ -279,7 +279,7 @@ namespace Nz
return (lua_compare(m_state, index1, index2, s_comparisons[comparison]) != 0);
}
void LuaInstance::Compute(LuaOperation operation)
void LuaInstance::Compute(LuaOperation operation) const
{
#ifdef NAZARA_DEBUG
if (operation > LuaOperation_Max)
@ -292,7 +292,7 @@ namespace Nz
lua_arith(m_state, s_operations[operation]);
}
void LuaInstance::Concatenate(int count)
void LuaInstance::Concatenate(int count) const
{
lua_concat(m_state, count);
}
@ -366,12 +366,12 @@ namespace Nz
return stream.ToString();
}
void LuaInstance::Error(const char* message)
void LuaInstance::Error(const char* message) const
{
luaL_error(m_state, message);
}
void LuaInstance::Error(const String& message)
void LuaInstance::Error(const String& message) const
{
luaL_error(m_state, message.GetConstBuffer());
}
@ -531,7 +531,7 @@ namespace Nz
return lua_typename(m_state, s_types[type]);
}
void LuaInstance::Insert(int index)
void LuaInstance::Insert(int index) const
{
lua_insert(m_state, index);
}
@ -596,7 +596,7 @@ namespace Nz
return luaL_len(m_state, index);
}
void LuaInstance::MoveTo(LuaInstance* instance, int n)
void LuaInstance::MoveTo(LuaInstance* instance, int n) const
{
lua_xmove(m_state, instance->m_state, n);
}
@ -611,27 +611,27 @@ namespace Nz
return luaL_newmetatable(m_state, str.GetConstBuffer()) != 0;
}
bool LuaInstance::Next(int index)
bool LuaInstance::Next(int index) const
{
return lua_next(m_state, index) != 0;
}
void LuaInstance::Pop(unsigned int n)
void LuaInstance::Pop(unsigned int n) const
{
lua_pop(m_state, static_cast<int>(n));
}
void LuaInstance::PushBoolean(bool value)
void LuaInstance::PushBoolean(bool value) const
{
lua_pushboolean(m_state, (value) ? 1 : 0);
}
void LuaInstance::PushCFunction(LuaCFunction func, unsigned int upvalueCount)
void LuaInstance::PushCFunction(LuaCFunction func, unsigned int upvalueCount) const
{
lua_pushcclosure(m_state, func, upvalueCount);
}
void LuaInstance::PushFunction(LuaFunction func)
void LuaInstance::PushFunction(LuaFunction func) const
{
LuaFunction* luaFunc = reinterpret_cast<LuaFunction*>(lua_newuserdata(m_state, sizeof(LuaFunction)));
PlacementNew<LuaFunction>(luaFunc, std::move(func));
@ -639,77 +639,77 @@ namespace Nz
lua_pushcclosure(m_state, ProxyFunc, 1);
}
void LuaInstance::PushInteger(long long value)
void LuaInstance::PushInteger(long long value) const
{
lua_pushinteger(m_state, value);
}
void LuaInstance::PushLightUserdata(void* value)
void LuaInstance::PushLightUserdata(void* value) const
{
lua_pushlightuserdata(m_state, value);
}
void LuaInstance::PushMetatable(const char* str)
void LuaInstance::PushMetatable(const char* str) const
{
luaL_getmetatable(m_state, str);
}
void LuaInstance::PushMetatable(const String& str)
void LuaInstance::PushMetatable(const String& str) const
{
luaL_getmetatable(m_state, str.GetConstBuffer());
}
void LuaInstance::PushNil()
void LuaInstance::PushNil() const
{
lua_pushnil(m_state);
}
void LuaInstance::PushNumber(double value)
void LuaInstance::PushNumber(double value) const
{
lua_pushnumber(m_state, value);
}
void LuaInstance::PushReference(int ref)
void LuaInstance::PushReference(int ref) const
{
lua_rawgeti(m_state, LUA_REGISTRYINDEX, ref);
}
void LuaInstance::PushString(const char* str)
void LuaInstance::PushString(const char* str) const
{
lua_pushstring(m_state, str);
}
void LuaInstance::PushString(const char* str, unsigned int size)
void LuaInstance::PushString(const char* str, unsigned int size) const
{
lua_pushlstring(m_state, str, size);
}
void LuaInstance::PushString(const String& str)
void LuaInstance::PushString(const String& str) const
{
lua_pushlstring(m_state, str.GetConstBuffer(), str.GetSize());
}
void LuaInstance::PushTable(unsigned int sequenceElementCount, unsigned int arrayElementCount)
void LuaInstance::PushTable(unsigned int sequenceElementCount, unsigned int arrayElementCount) const
{
lua_createtable(m_state, sequenceElementCount, arrayElementCount);
}
void* LuaInstance::PushUserdata(unsigned int size)
void* LuaInstance::PushUserdata(unsigned int size) const
{
return lua_newuserdata(m_state, size);
}
void LuaInstance::PushValue(int index)
void LuaInstance::PushValue(int index) const
{
lua_pushvalue(m_state, index);
}
void LuaInstance::Remove(int index)
void LuaInstance::Remove(int index) const
{
lua_remove(m_state, index);
}
void LuaInstance::Replace(int index)
void LuaInstance::Replace(int index) const
{
lua_replace(m_state, index);
}
@ -734,17 +734,17 @@ namespace Nz
lua_setglobal(m_state, name.GetConstBuffer());
}
void LuaInstance::SetMetatable(const char* tname)
void LuaInstance::SetMetatable(const char* tname) const
{
luaL_setmetatable(m_state, tname);
}
void LuaInstance::SetMetatable(const String& tname)
void LuaInstance::SetMetatable(const String& tname) const
{
luaL_setmetatable(m_state, tname.GetConstBuffer());
}
void LuaInstance::SetMetatable(int index)
void LuaInstance::SetMetatable(int index) const
{
lua_setmetatable(m_state, index);
}