Skip to content

Commit

Permalink
Replace method table loop and remove empty end of array entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Foereaper committed Aug 6, 2024
1 parent d673864 commit 509f6ac
Show file tree
Hide file tree
Showing 77 changed files with 89 additions and 239 deletions.
22 changes: 12 additions & 10 deletions ElunaTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct ElunaRegister
: name(name), mfunc(func), regState(state) {}

// constructor for nullptr functions and METHOD_REG_NONE (unimplemented methods)
ElunaRegister(const char* name = nullptr, MethodRegisterState state = METHOD_REG_NONE)
ElunaRegister(const char* name, MethodRegisterState state = METHOD_REG_NONE)
: name(name), mfunc(nullptr), regState(state) {}
};

Expand Down Expand Up @@ -277,8 +277,8 @@ class ElunaTemplate
lua_pop(E->L, 1);
}

template<typename C>
static void SetMethods(Eluna* E, ElunaRegister<C>* methodTable)
template<typename C, size_t N>
static void SetMethods(Eluna* E, ElunaRegister<C> const (&methodTable)[N])
{
ASSERT(E);
ASSERT(methodTable);
Expand All @@ -301,25 +301,27 @@ class ElunaTemplate
}

// load all core-specific methods
for (; methodTable && methodTable->name; ++methodTable)
for (int i = 0; i < N; i++)
{
const auto& method = methodTable + i;

// push the method name to the Lua stack
lua_pushstring(E->L, methodTable->name);
lua_pushstring(E->L, method->name);

// if the method should not be registered, push a closure to error output function
if (methodTable->regState == METHOD_REG_NONE)
if (method->regState == METHOD_REG_NONE)
{
lua_pushcclosure(E->L, MethodUnimpl, 0);
lua_rawset(E->L, -3);
continue;
}

// if we're in multistate mode, we need to check whether a method is flagged as a world or a map specific method
if (!E->GetCompatibilityMode() && methodTable->regState != METHOD_REG_ALL)
if (!E->GetCompatibilityMode() && method->regState != METHOD_REG_ALL)
{
// if the method should not be registered, push a closure to error output function
if ((E->GetBoundMapId() == -1 && methodTable->regState == METHOD_REG_MAP) ||
(E->GetBoundMapId() != -1 && methodTable->regState == METHOD_REG_WORLD))
if ((E->GetBoundMapId() == -1 && method->regState == METHOD_REG_MAP) ||
(E->GetBoundMapId() != -1 && method->regState == METHOD_REG_WORLD))
{
lua_pushcclosure(E->L, MethodWrongState, 0);
lua_rawset(E->L, -3);
Expand All @@ -328,7 +330,7 @@ class ElunaTemplate
}

// push method table and Eluna object pointers as light user data
lua_pushlightuserdata(E->L, (void*)methodTable);
lua_pushlightuserdata(E->L, (void*)method);
lua_pushlightuserdata(E->L, (void*)E);

// push a closure to the thunk function with 2 upvalues (method table and Eluna object)
Expand Down
4 changes: 1 addition & 3 deletions methods/CMangos/AuraMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ namespace LuaAura
{ "SetStackAmount", &LuaAura::SetStackAmount },

// Other
{ "Remove", &LuaAura::Remove },

{ nullptr, METHOD_REG_NONE }
{ "Remove", &LuaAura::Remove }
};
};
#endif
4 changes: 1 addition & 3 deletions methods/CMangos/BattleGroundMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ namespace LuaBattleGround
{ "GetMaxPlayersPerTeam", &LuaBattleGround::GetMaxPlayersPerTeam },
{ "GetMinPlayersPerTeam", &LuaBattleGround::GetMinPlayersPerTeam },
{ "GetWinner", &LuaBattleGround::GetWinner },
{ "GetStatus", &LuaBattleGround::GetStatus },

{ nullptr, METHOD_REG_NONE }
{ "GetStatus", &LuaBattleGround::GetStatus }
};
};
#endif
4 changes: 1 addition & 3 deletions methods/CMangos/CorpseMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ namespace LuaCorpse

// Other
{ "ResetGhostTime", &LuaCorpse::ResetGhostTime },
{ "SaveToDB", &LuaCorpse::SaveToDB },

{ nullptr, METHOD_REG_NONE }
{ "SaveToDB", &LuaCorpse::SaveToDB }
};
};
#endif
4 changes: 1 addition & 3 deletions methods/CMangos/CreatureMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -1308,9 +1308,7 @@ namespace LuaCreature
{ "ClearThreat", METHOD_REG_NONE }, // TC/Acore
{ "ResetAllThreat", METHOD_REG_NONE }, // TC/Acore
{ "FixateTarget", METHOD_REG_NONE }, // TC/Acore
{ "ClearFixate", METHOD_REG_NONE }, // TC/Acore

{ nullptr, METHOD_REG_NONE }
{ "ClearFixate", METHOD_REG_NONE } // TC/Acore
};
};
#endif
4 changes: 1 addition & 3 deletions methods/CMangos/ElunaQueryMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,7 @@ namespace LuaQuery

// Boolean
{ "NextRow", &LuaQuery::NextRow },
{ "IsNull", &LuaQuery::IsNull },

{ nullptr, METHOD_REG_NONE }
{ "IsNull", &LuaQuery::IsNull }
};
};
#undef RESULT
Expand Down
4 changes: 1 addition & 3 deletions methods/CMangos/GameObjectMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,7 @@ namespace LuaGameObject
{ "SaveToDB", &LuaGameObject::SaveToDB },

// Not implemented methods
{ "IsDestructible", METHOD_REG_NONE }, // Not implemented

{ nullptr, METHOD_REG_NONE }
{ "IsDestructible", METHOD_REG_NONE } // Not implemented
};
};
#endif
4 changes: 1 addition & 3 deletions methods/CMangos/GlobalMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -3295,9 +3295,7 @@ namespace LuaGlobalFunctions
{ "CreateInt64", &LuaGlobalFunctions::CreateLongLong },
{ "CreateUint64", &LuaGlobalFunctions::CreateULongLong },
{ "StartGameEvent", &LuaGlobalFunctions::StartGameEvent },
{ "StopGameEvent", &LuaGlobalFunctions::StopGameEvent },

{ nullptr, METHOD_REG_NONE }
{ "StopGameEvent", &LuaGlobalFunctions::StopGameEvent }
};
}
#endif
4 changes: 1 addition & 3 deletions methods/CMangos/GroupMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,7 @@ namespace LuaGroup
{ "IsBFGroup", METHOD_REG_NONE }, // not implemented
{ "ConvertToLFG", METHOD_REG_NONE }, // not implemented
{ "GetMemberFlags", METHOD_REG_NONE }, // not implemented
{ "SetMemberFlag", METHOD_REG_NONE }, // not implemented

{ nullptr, METHOD_REG_NONE }
{ "SetMemberFlag", METHOD_REG_NONE } // not implemented
};
};

Expand Down
4 changes: 1 addition & 3 deletions methods/CMangos/GuildMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,7 @@ namespace LuaGuild
{ "SendPacketToRanked", &LuaGuild::SendPacketToRanked },
{ "Disband", &LuaGuild::Disband, METHOD_REG_WORLD }, // World state method only in multistate
{ "AddMember", &LuaGuild::AddMember, METHOD_REG_WORLD }, // World state method only in multistate
{ "DeleteMember", &LuaGuild::DeleteMember, METHOD_REG_WORLD }, // World state method only in multistate

{ nullptr, METHOD_REG_NONE }
{ "DeleteMember", &LuaGuild::DeleteMember, METHOD_REG_WORLD } // World state method only in multistate
};
};
#endif
4 changes: 1 addition & 3 deletions methods/CMangos/ItemMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -858,9 +858,7 @@ namespace LuaItem
{ "SaveToDB", &LuaItem::SaveToDB },

// Not implemented methods
{ "IsRefundExpired", METHOD_REG_NONE }, // not implemented

{ nullptr, METHOD_REG_NONE }
{ "IsRefundExpired", METHOD_REG_NONE } // not implemented
};
};
#endif
4 changes: 1 addition & 3 deletions methods/CMangos/MapMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,7 @@ namespace LuaMap

// Other
{ "SaveInstanceData", &LuaMap::SaveInstanceData },
{ "Data", &LuaMap::Data },

{ nullptr, METHOD_REG_NONE }
{ "Data", &LuaMap::Data }
};
};
#endif
4 changes: 1 addition & 3 deletions methods/CMangos/ObjectMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,7 @@ namespace LuaObject
{ "ToCreature", &LuaObject::ToCreature },
{ "ToPlayer", &LuaObject::ToPlayer },
{ "ToCorpse", &LuaObject::ToCorpse },
{ "RemoveFlag", &LuaObject::RemoveFlag },

{ nullptr, METHOD_REG_NONE }
{ "RemoveFlag", &LuaObject::RemoveFlag }
};
};
#endif
4 changes: 1 addition & 3 deletions methods/CMangos/PlayerMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -4059,9 +4059,7 @@ namespace LuaPlayer
{ "ResetHonor", METHOD_REG_NONE }, // classic only
{ "ClearHonorInfo", METHOD_REG_NONE }, // classic only
{ "GetXP", METHOD_REG_NONE }, // not implemented
{ "GetXPForNextLevel", METHOD_REG_NONE }, // not implemented

{ nullptr, METHOD_REG_NONE }
{ "GetXPForNextLevel", METHOD_REG_NONE } // not implemented
};
};
#endif
4 changes: 1 addition & 3 deletions methods/CMangos/QuestMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ namespace LuaQuest
{ "IsRepeatable", &LuaQuest::IsRepeatable },

// Not implemented methods
{ "GetMaxLevel", METHOD_REG_NONE }, // not implemented

{ nullptr, METHOD_REG_NONE }
{ "GetMaxLevel", METHOD_REG_NONE } // not implemented
};
};
#endif
4 changes: 1 addition & 3 deletions methods/CMangos/SpellMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,7 @@ namespace LuaSpell
// Other
{ "Cancel", &LuaSpell::Cancel },
{ "Cast", &LuaSpell::Cast },
{ "Finish", &LuaSpell::Finish },

{ nullptr, METHOD_REG_NONE }
{ "Finish", &LuaSpell::Finish }
};
};
#endif
4 changes: 1 addition & 3 deletions methods/CMangos/UnitMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -2609,9 +2609,7 @@ namespace LuaUnit
{ "RemoveBindSightAuras", METHOD_REG_NONE }, // not implemented
{ "RemoveCharmAuras", METHOD_REG_NONE }, // not implemented
{ "DisableMelee", METHOD_REG_NONE }, // not implemented
{ "SummonGuardian", METHOD_REG_NONE }, // not implemented

{ nullptr, METHOD_REG_NONE }
{ "SummonGuardian", METHOD_REG_NONE } // not implemented
};
};
#endif
4 changes: 1 addition & 3 deletions methods/CMangos/VehicleMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ namespace LuaVehicle

// Other
{ "AddPassenger", &LuaVehicle::AddPassenger },
{ "RemovePassenger", &LuaVehicle::RemovePassenger },

{ nullptr, METHOD_REG_NONE }
{ "RemovePassenger", &LuaVehicle::RemovePassenger }
};
}

Expand Down
4 changes: 1 addition & 3 deletions methods/CMangos/WorldObjectMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -1185,9 +1185,7 @@ namespace LuaWorldObject
{ "PlayMusic", &LuaWorldObject::PlayMusic },
{ "PlayDirectSound", &LuaWorldObject::PlayDirectSound },
{ "PlayDistanceSound", &LuaWorldObject::PlayDistanceSound },
{ "Data", &LuaWorldObject::Data },

{ nullptr, METHOD_REG_NONE }
{ "Data", &LuaWorldObject::Data }
};
};
#endif
4 changes: 1 addition & 3 deletions methods/CMangos/WorldPacketMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,7 @@ namespace LuaPacket
{ "WriteGUID", &LuaPacket::WriteGUID },
{ "WriteString", &LuaPacket::WriteString },
{ "WriteFloat", &LuaPacket::WriteFloat },
{ "WriteDouble", &LuaPacket::WriteDouble },

{ nullptr, METHOD_REG_NONE }
{ "WriteDouble", &LuaPacket::WriteDouble }
};
};

Expand Down
4 changes: 1 addition & 3 deletions methods/Mangos/AuraMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ namespace LuaAura
{ "SetStackAmount", &LuaAura::SetStackAmount },

// Other
{ "Remove", &LuaAura::Remove },

{ nullptr, METHOD_REG_NONE }
{ "Remove", &LuaAura::Remove }
};
};
#endif
4 changes: 1 addition & 3 deletions methods/Mangos/BattleGroundMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,7 @@ namespace LuaBattleGround
{ "GetMaxPlayersPerTeam", &LuaBattleGround::GetMaxPlayersPerTeam },
{ "GetMinPlayersPerTeam", &LuaBattleGround::GetMinPlayersPerTeam },
{ "GetWinner", &LuaBattleGround::GetWinner },
{ "GetStatus", &LuaBattleGround::GetStatus },

{ nullptr, METHOD_REG_NONE }
{ "GetStatus", &LuaBattleGround::GetStatus }
};
};
#endif
4 changes: 1 addition & 3 deletions methods/Mangos/CorpseMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ namespace LuaCorpse

// Other
{ "ResetGhostTime", &LuaCorpse::ResetGhostTime },
{ "SaveToDB", &LuaCorpse::SaveToDB },

{ nullptr, METHOD_REG_NONE }
{ "SaveToDB", &LuaCorpse::SaveToDB }
};
};
#endif
4 changes: 1 addition & 3 deletions methods/Mangos/CreatureMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -1206,9 +1206,7 @@ namespace LuaCreature
{ "ResetLootMode", METHOD_REG_NONE }, // not implemented
{ "RemoveLootMode", METHOD_REG_NONE }, // not implemented
{ "RemoveFromWorld", METHOD_REG_NONE }, // not implemented
{ "GetRank", METHOD_REG_NONE }, // not implemented

{ nullptr, METHOD_REG_NONE }
{ "GetRank", METHOD_REG_NONE } // not implemented
};
};
#endif
4 changes: 1 addition & 3 deletions methods/Mangos/ElunaQueryMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,7 @@ namespace LuaQuery

// Boolean
{ "NextRow", &LuaQuery::NextRow },
{ "IsNull", &LuaQuery::IsNull },

{ nullptr, METHOD_REG_NONE }
{ "IsNull", &LuaQuery::IsNull }
};
};
#undef RESULT
Expand Down
4 changes: 1 addition & 3 deletions methods/Mangos/GameObjectMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,7 @@ namespace LuaGameObject
{ "SaveToDB", &LuaGameObject::SaveToDB },

// Not implemented methods
{ "IsDestructible", METHOD_REG_NONE }, // Not implemented

{ nullptr, METHOD_REG_NONE }
{ "IsDestructible", METHOD_REG_NONE } // Not implemented
};
};
#endif
4 changes: 1 addition & 3 deletions methods/Mangos/GlobalMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -3039,9 +3039,7 @@ namespace LuaGlobalFunctions
// unimplemented
{ "WorldDBQueryAsync", METHOD_REG_NONE },
{ "CharDBQueryAsync", METHOD_REG_NONE },
{ "AuthDBQueryAsync", METHOD_REG_NONE },

{ nullptr, METHOD_REG_NONE }
{ "AuthDBQueryAsync", METHOD_REG_NONE }
};
}
#endif
4 changes: 1 addition & 3 deletions methods/Mangos/GroupMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,7 @@ namespace LuaGroup
{ "IsBFGroup", METHOD_REG_NONE }, // not implemented
{ "ConvertToLFG", METHOD_REG_NONE }, // not implemented
{ "GetMemberFlags", METHOD_REG_NONE }, // not implemented
{ "SetMemberFlag", METHOD_REG_NONE }, // not implemented

{ nullptr, METHOD_REG_NONE }
{ "SetMemberFlag", METHOD_REG_NONE } // not implemented
};
};

Expand Down
4 changes: 1 addition & 3 deletions methods/Mangos/GuildMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,7 @@ namespace LuaGuild
{ "SendPacketToRanked", &LuaGuild::SendPacketToRanked },
{ "Disband", &LuaGuild::Disband, METHOD_REG_WORLD }, // World state method only in multistate
{ "AddMember", &LuaGuild::AddMember, METHOD_REG_WORLD }, // World state method only in multistate
{ "DeleteMember", &LuaGuild::DeleteMember, METHOD_REG_WORLD }, // World state method only in multistate

{ nullptr, METHOD_REG_NONE }
{ "DeleteMember", &LuaGuild::DeleteMember, METHOD_REG_WORLD } // World state method only in multistate
};
};
#endif
4 changes: 1 addition & 3 deletions methods/Mangos/ItemMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -867,9 +867,7 @@ namespace LuaItem
{ "SaveToDB", &LuaItem::SaveToDB },

// Not implemented methods
{ "IsRefundExpired", METHOD_REG_NONE }, // not implemented

{ nullptr, METHOD_REG_NONE }
{ "IsRefundExpired", METHOD_REG_NONE } // not implemented
};
};
#endif
4 changes: 1 addition & 3 deletions methods/Mangos/MapMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,7 @@ namespace LuaMap
#endif
// Other
{ "SaveInstanceData", &LuaMap::SaveInstanceData },
{ "Data", &LuaMap::Data },

{ nullptr, METHOD_REG_NONE }
{ "Data", &LuaMap::Data }
};
};
#endif
Loading

0 comments on commit 509f6ac

Please sign in to comment.