Lua/LuaInstance: Rename automatic SetField/SetGlobal to PushField/PushGlobal

Former-commit-id: add576baa5ee7c12121925b5b4fb5fc37fe85042
This commit is contained in:
Lynix 2016-04-23 22:18:43 +02:00
parent 3051b6bdde
commit 7b10bbaab0
4 changed files with 38 additions and 38 deletions

View File

@ -90,10 +90,10 @@ namespace Ndk
{ {
instance.PushInteger(index++); instance.PushInteger(index++);
instance.PushTable(0, 4); instance.PushTable(0, 4);
instance.SetField("Address", std::move(info.address)); instance.PushField("Address", std::move(info.address));
instance.SetField("CanonicalName", std::move(info.canonicalName)); instance.PushField("CanonicalName", std::move(info.canonicalName));
instance.SetField("Protocol", std::move(info.protocol)); instance.PushField("Protocol", std::move(info.protocol));
instance.SetField("SocketType", std::move(info.socketType)); instance.PushField("SocketType", std::move(info.socketType));
instance.SetTable(); instance.SetTable();
} }

View File

@ -125,8 +125,12 @@ namespace Nz
template<typename T> int Push(T arg) const; template<typename T> int Push(T arg) const;
void PushBoolean(bool value) const; void PushBoolean(bool value) const;
void PushCFunction(LuaCFunction func, unsigned int upvalueCount = 0) const; void PushCFunction(LuaCFunction func, unsigned int upvalueCount = 0) const;
template<typename T> void PushField(const char* name, T&& arg, int tableIndex = -2) const;
template<typename T> void PushField(const String& name, T&& arg, int tableIndex = -2) const;
void PushFunction(LuaFunction func) const; void PushFunction(LuaFunction func) const;
template<typename R, typename... Args, typename... DefArgs> void PushFunction(R(*func)(Args...), DefArgs&&... defArgs) const; 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, T* instance) const;
template<typename T, typename... Args> void PushInstance(const char* tname, Args&&... args) const; template<typename T, typename... Args> void PushInstance(const char* tname, Args&&... args) const;
void PushInteger(long long value) const; void PushInteger(long long value) const;
@ -146,12 +150,8 @@ namespace Nz
void Remove(int index) const; void Remove(int index) const;
void Replace(int index) const; void Replace(int index) const;
template<typename T> void SetField(const char* name, T&& arg, int tableIndex = -2); void SetField(const char* name, int tableIndex = -2) const;
template<typename T> void SetField(const String& name, T&& arg, int tableIndex = -2); void SetField(const String& name, int tableIndex = -2) const;
void SetField(const char* name, int tableIndex = -2);
void SetField(const String& name, int tableIndex = -2);
template<typename T> void SetGlobal(const char* name, T&& arg);
template<typename T> void SetGlobal(const String& name, T&& arg);
void SetGlobal(const char* name); void SetGlobal(const char* name);
void SetGlobal(const String& name); void SetGlobal(const String& name);
void SetMetatable(const char* tname) const; void SetMetatable(const char* tname) const;

View File

@ -541,6 +541,19 @@ namespace Nz
return LuaImplReplyVal(*this, std::move(arg), TypeTag<T>()); return LuaImplReplyVal(*this, std::move(arg), TypeTag<T>());
} }
template<typename T>
void LuaInstance::PushField(const char* name, T&& arg, int tableIndex) const
{
Push<T>(std::forward<T>(arg));
SetField(name, tableIndex);
}
template<typename T>
void LuaInstance::PushField(const String& name, T&& arg, int tableIndex) const
{
PushField(name.GetConstBuffer(), std::forward<T>(arg), tableIndex);
}
template<typename R, typename... Args, typename... DefArgs> template<typename R, typename... Args, typename... DefArgs>
void LuaInstance::PushFunction(R(*func)(Args...), DefArgs&&... defArgs) const void LuaInstance::PushFunction(R(*func)(Args...), DefArgs&&... defArgs) const
{ {
@ -554,6 +567,19 @@ namespace Nz
}); });
} }
template<typename T>
void LuaInstance::PushGlobal(const char* name, T&& arg)
{
Push<T>(std::forward<T>(arg));
SetGlobal(name);
}
template<typename T>
void LuaInstance::PushGlobal(const String& name, T&& arg)
{
PushGlobal(name.GetConstBuffer(), std::forward<T>(arg));
}
template<typename T> template<typename T>
void LuaInstance::PushInstance(const char* tname, T* instance) const void LuaInstance::PushInstance(const char* tname, T* instance) const
{ {
@ -568,32 +594,6 @@ namespace Nz
PushInstance(tname, new T(std::forward<Args>(args)...)); PushInstance(tname, new T(std::forward<Args>(args)...));
} }
template<typename T>
void LuaInstance::SetField(const char* name, T&& arg, int tableIndex)
{
Push<T>(std::forward<T>(arg));
SetField(name, tableIndex);
}
template<typename T>
void LuaInstance::SetField(const String& name, T&& arg, int tableIndex)
{
SetField(name.GetConstBuffer(), std::forward<T>(arg), tableIndex);
}
template<typename T>
void LuaInstance::SetGlobal(const char* name, T&& arg)
{
Push<T>(std::forward<T>(arg));
SetGlobal(name);
}
template<typename T>
void LuaInstance::SetGlobal(const String& name, T&& arg)
{
SetGlobal(name.GetConstBuffer(), std::forward<T>(arg));
}
template<typename T> template<typename T>
T LuaInstance::CheckBounds(int index, long long value) const T LuaInstance::CheckBounds(int index, long long value) const
{ {

View File

@ -714,12 +714,12 @@ namespace Nz
lua_replace(m_state, index); lua_replace(m_state, index);
} }
void LuaInstance::SetField(const char* name, int tableIndex) void LuaInstance::SetField(const char* name, int tableIndex) const
{ {
lua_setfield(m_state, tableIndex, name); lua_setfield(m_state, tableIndex, name);
} }
void LuaInstance::SetField(const String& name, int tableIndex) void LuaInstance::SetField(const String& name, int tableIndex) const
{ {
lua_setfield(m_state, tableIndex, name.GetConstBuffer()); lua_setfield(m_state, tableIndex, name.GetConstBuffer());
} }