summaryrefslogtreecommitdiffstats
path: root/src/Bindings/LuaNameLookup.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-08-14 09:51:37 +0200
committerGitHub <noreply@github.com>2016-08-14 09:51:37 +0200
commit0a58d1de583dafd8d81251f2f5ac23159726990b (patch)
tree68f7279d31a2147962db6b26cab6554ac262a198 /src/Bindings/LuaNameLookup.cpp
parentRevert "Added a BasicStyleCheck for virtual functions without override keyword." (diff)
parentIPLookup: Fixed a soft memory leak when looking up invalid IPs. (diff)
downloadcuberite-0a58d1de583dafd8d81251f2f5ac23159726990b.tar
cuberite-0a58d1de583dafd8d81251f2f5ac23159726990b.tar.gz
cuberite-0a58d1de583dafd8d81251f2f5ac23159726990b.tar.bz2
cuberite-0a58d1de583dafd8d81251f2f5ac23159726990b.tar.lz
cuberite-0a58d1de583dafd8d81251f2f5ac23159726990b.tar.xz
cuberite-0a58d1de583dafd8d81251f2f5ac23159726990b.tar.zst
cuberite-0a58d1de583dafd8d81251f2f5ac23159726990b.zip
Diffstat (limited to 'src/Bindings/LuaNameLookup.cpp')
-rw-r--r--src/Bindings/LuaNameLookup.cpp50
1 files changed, 5 insertions, 45 deletions
diff --git a/src/Bindings/LuaNameLookup.cpp b/src/Bindings/LuaNameLookup.cpp
index 3cbdbb5cf..3f55e7bc8 100644
--- a/src/Bindings/LuaNameLookup.cpp
+++ b/src/Bindings/LuaNameLookup.cpp
@@ -10,9 +10,8 @@
-cLuaNameLookup::cLuaNameLookup(const AString & a_Query, cPluginLua & a_Plugin, int a_CallbacksTableStackPos):
- m_Plugin(a_Plugin),
- m_Callbacks(cPluginLua::cOperation(a_Plugin)(), a_CallbacksTableStackPos),
+cLuaNameLookup::cLuaNameLookup(const AString & a_Query, cLuaState::cTableRefPtr && a_Callbacks):
+ m_Callbacks(std::move(a_Callbacks)),
m_Query(a_Query)
{
}
@@ -23,20 +22,7 @@ cLuaNameLookup::cLuaNameLookup(const AString & a_Query, cPluginLua & a_Plugin, i
void cLuaNameLookup::OnNameResolved(const AString & a_Name, const AString & a_IP)
{
- // Check if we're still valid:
- if (!m_Callbacks.IsValid())
- {
- return;
- }
-
- // Call the callback:
- cPluginLua::cOperation Op(m_Plugin);
- if (!Op().Call(cLuaState::cTableRef(m_Callbacks, "OnNameResolved"), a_Name, a_IP))
- {
- LOGINFO("cNetwork name lookup OnNameResolved callback failed in plugin %s looking up %s. %s resolves to %s.",
- m_Plugin.GetName().c_str(), m_Query.c_str(), a_Name.c_str(), a_IP.c_str()
- );
- }
+ m_Callbacks->CallTableFn("OnNameResolved", a_Name, a_IP);
}
@@ -45,20 +31,7 @@ void cLuaNameLookup::OnNameResolved(const AString & a_Name, const AString & a_IP
void cLuaNameLookup::OnError(int a_ErrorCode, const AString & a_ErrorMsg)
{
- // Check if we're still valid:
- if (!m_Callbacks.IsValid())
- {
- return;
- }
-
- // Call the callback:
- cPluginLua::cOperation Op(m_Plugin);
- if (!Op().Call(cLuaState::cTableRef(m_Callbacks, "OnError"), m_Query, a_ErrorCode, a_ErrorMsg))
- {
- LOGINFO("cNetwork name lookup OnError callback failed in plugin %s looking up %s. The error is %d (%s)",
- m_Plugin.GetName().c_str(), m_Query.c_str(), a_ErrorCode, a_ErrorMsg.c_str()
- );
- }
+ m_Callbacks->CallTableFn("OnError", m_Query, a_ErrorCode, a_ErrorMsg);
}
@@ -67,20 +40,7 @@ void cLuaNameLookup::OnError(int a_ErrorCode, const AString & a_ErrorMsg)
void cLuaNameLookup::OnFinished(void)
{
- // Check if we're still valid:
- if (!m_Callbacks.IsValid())
- {
- return;
- }
-
- // Call the callback:
- cPluginLua::cOperation Op(m_Plugin);
- if (!Op().Call(cLuaState::cTableRef(m_Callbacks, "OnFinished"), m_Query))
- {
- LOGINFO("cNetwork name lookup OnFinished callback failed in plugin %s, looking up %s.",
- m_Plugin.GetName().c_str(), m_Query.c_str()
- );
- }
+ m_Callbacks->CallTableFn("OnFinished", m_Query);
}