Lua/LuaClass: Fix static methods

This commit is contained in:
Lynix 2016-10-25 13:14:16 +02:00
parent fa7d6a10b0
commit b5a32d7eb2
1 changed files with 21 additions and 12 deletions

View File

@ -279,17 +279,10 @@ namespace Nz
template<class T> template<class T>
void LuaClass<T>::SetupGetter(LuaInstance& lua, LuaCFunction proxy) void LuaClass<T>::SetupGetter(LuaInstance& lua, LuaCFunction proxy)
{
if (m_info->getter || !m_info->parentGetters.empty())
{ {
lua.PushValue(1); // ClassInfo lua.PushValue(1); // ClassInfo
lua.PushValue(-2); // Metatable lua.PushValue(-2); // Metatable
lua.PushCFunction(proxy, 2); lua.PushCFunction(proxy, 2);
}
else
// Optimize by assigning the metatable instead of a search function
// This is only possible if we have no custom getter nor parent
lua.PushValue(-1); // Metatable
lua.SetField("__index"); // Getter lua.SetField("__index"); // Getter
} }
@ -306,7 +299,14 @@ namespace Nz
if (m_info->constructor) if (m_info->constructor)
SetupConstructor(lua); SetupConstructor(lua);
if (m_info->staticGetter)
SetupGetter(lua, StaticGetterProxy); SetupGetter(lua, StaticGetterProxy);
else
{
// Optimize by assigning the metatable instead of a search function
lua.PushValue(-1); // Metatable
lua.SetField("__index");
}
if (m_info->staticSetter) if (m_info->staticSetter)
SetupSetter(lua, StaticSetterProxy); SetupSetter(lua, StaticSetterProxy);
@ -335,7 +335,16 @@ namespace Nz
NazaraWarning("Class \"" + m_info->name + "\" already registred in this instance"); NazaraWarning("Class \"" + m_info->name + "\" already registred in this instance");
{ {
SetupFinalizer(lua); SetupFinalizer(lua);
if (m_info->getter || !m_info->parentGetters.empty())
SetupGetter(lua, GetterProxy); SetupGetter(lua, GetterProxy);
else
{
// Optimize by assigning the metatable instead of a search function
// This is only possible if we have no custom getter nor parent
lua.PushValue(-1); // Metatable
lua.SetField("__index");
}
if (m_info->setter) if (m_info->setter)
SetupSetter(lua, SetterProxy); SetupSetter(lua, SetterProxy);