mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-16 07:07:13 +02:00
Refactor.
This commit is contained in:
@ -661,7 +661,7 @@ Int32 SQLiteConnHnd::Flush(Uint32 num, Object & env, Function & func)
|
||||
num = mQueue.size();
|
||||
}
|
||||
// Generate the function that should be called upon error
|
||||
Function callback = Function(env.GetVM(), env.GetObj(), func.GetFunc());
|
||||
Function callback = Function(env.GetObj(), func.GetFunc(), env.GetVM());
|
||||
// Obtain iterators to the range of queries that should be flushed
|
||||
auto itr = mQueue.begin();
|
||||
auto end = mQueue.begin() + num;
|
||||
|
@ -280,7 +280,7 @@ void Logger::SetLogFilename(CCStr filename)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Logger::BindCb(Uint8 level, Object & env, Function & func)
|
||||
void Logger::BindCb(Uint8 level, Function & func)
|
||||
{
|
||||
// Get the index of this log level
|
||||
const Uint8 idx = GetLevelIdx(level);
|
||||
@ -291,24 +291,8 @@ void Logger::BindCb(Uint8 level, Object & env, Function & func)
|
||||
}
|
||||
// Obtain the function instance called for this log level
|
||||
Function & cb = m_LogCb[idx];
|
||||
// Is the specified callback function null?
|
||||
if (func.IsNull())
|
||||
{
|
||||
cb.Release(); // Then release the current callback
|
||||
}
|
||||
// Does this function need a custom environment?
|
||||
else if (env.IsNull())
|
||||
{
|
||||
// Use the root table instead
|
||||
RootTable root(SqVM());
|
||||
// Bind the root table with the function
|
||||
cb = Function(env.GetVM(), root, func.GetFunc());
|
||||
}
|
||||
// Assign the specified environment and function
|
||||
else
|
||||
{
|
||||
cb = Function(env.GetVM(), env, func.GetFunc());
|
||||
}
|
||||
cb = std::move(func);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -753,9 +737,9 @@ template < Uint8 L, bool S > static SQInteger LogBasicMessage(HSQUIRRELVM vm)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template < Uint8 L > static void BindLogCallback(Object & env, Function & func)
|
||||
template < Uint8 L > static void BindLogCallback(Function & func)
|
||||
{
|
||||
Logger::Get().BindCb(L, env, func);
|
||||
Logger::Get().BindCb(L, func);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -293,7 +293,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Bind a script callback to a log level.
|
||||
*/
|
||||
void BindCb(Uint8 level, Object & env, Function & func);
|
||||
void BindCb(Uint8 level, Function & func);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Send a log message.
|
||||
|
@ -370,18 +370,13 @@ Vector2i AreaManager::LocateCell(float x, float y)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static void Areas_TestPointEx(Object & env, Function & func, float x, float y)
|
||||
static void Areas_TestPointEx(float x, float y, Function & func)
|
||||
{
|
||||
// Is the function valid?
|
||||
if (func.IsNull())
|
||||
{
|
||||
STHROWF("Invalid callback object");
|
||||
}
|
||||
// Should we use a custom environment?
|
||||
else if (!env.IsNull())
|
||||
{
|
||||
func = Function(env.GetVM(), env, func.GetFunc());
|
||||
}
|
||||
// Begin testing
|
||||
AreaManager::Get().TestPoint([&func](AreaCell::Areas::reference ap) -> void {
|
||||
func.Execute(ap.second);
|
||||
@ -389,24 +384,14 @@ static void Areas_TestPointEx(Object & env, Function & func, float x, float y)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static void Areas_TestPoint(Object & env, Function & func, const Vector2 & v)
|
||||
static void Areas_TestPoint(const Vector2 & v, Function & func)
|
||||
{
|
||||
Areas_TestPointEx(env, func, v.x, v.y);
|
||||
Areas_TestPointEx(v.x, v.y, func);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static void Areas_TestPointOnEx(Object & ctx, Object & env, Function & func, float x, float y)
|
||||
static void Areas_TestPointOnEx(float x, float y, Object & ctx, Function & func)
|
||||
{
|
||||
// Is the function valid?
|
||||
if (func.IsNull())
|
||||
{
|
||||
STHROWF("Invalid callback object");
|
||||
}
|
||||
// Should we use a custom environment?
|
||||
else if (!env.IsNull())
|
||||
{
|
||||
func = Function(env.GetVM(), env, func.GetFunc());
|
||||
}
|
||||
// Begin testing
|
||||
AreaManager::Get().TestPoint([&ctx, &func](AreaCell::Areas::reference ap) -> void {
|
||||
func.Execute(ctx, ap.second);
|
||||
@ -414,9 +399,9 @@ static void Areas_TestPointOnEx(Object & ctx, Object & env, Function & func, flo
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static void Areas_TestPointOn(Object & ctx, Object & env, Function & func, const Vector2 & v)
|
||||
static void Areas_TestPointOn(const Vector2 & v, Object & ctx, Function & func)
|
||||
{
|
||||
Areas_TestPointOnEx(ctx, env, func, v.x, v.y);
|
||||
Areas_TestPointOnEx(v.x, v.y, ctx, func);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -1048,11 +1048,11 @@ void Register(HSQUIRRELVM vm)
|
||||
.Func(_SC("Clear"), &Manager::Clear)
|
||||
.Func(_SC("Attach"), &Manager::Attach)
|
||||
.FmtFunc(_SC("FindByName"), &Manager::FindByName)
|
||||
.Func(_SC("BindFail"), &Manager::SetOnFail)
|
||||
.Func(_SC("BindAuth"), &Manager::SetOnAuth)
|
||||
.CbFunc(_SC("BindFail"), &Manager::SetOnFail)
|
||||
.CbFunc(_SC("BindAuth"), &Manager::SetOnAuth)
|
||||
.Func(_SC("GetArray"), &Manager::GetCommandsArray)
|
||||
.Func(_SC("GetTable"), &Manager::GetCommandsTable)
|
||||
.Func(_SC("Foreach"), &Manager::ForeachCommand)
|
||||
.CbFunc(_SC("Foreach"), &Manager::ForeachCommand)
|
||||
// Member Overloads
|
||||
.Overload(_SC("Create"), &Manager::Create1)
|
||||
.Overload(_SC("Create"), &Manager::Create2)
|
||||
@ -1107,10 +1107,10 @@ void Register(HSQUIRRELVM vm)
|
||||
.FmtFunc(_SC("SetSpec"), &Listener::SetSpec)
|
||||
.FmtFunc(_SC("SetHelp"), &Listener::SetHelp)
|
||||
.FmtFunc(_SC("SetInfo"), &Listener::SetInfo)
|
||||
.Func(_SC("BindExec"), &Listener::SetOnExec)
|
||||
.Func(_SC("BindAuth"), &Listener::SetOnAuth)
|
||||
.Func(_SC("BindPost"), &Listener::SetOnPost)
|
||||
.Func(_SC("BindFail"), &Listener::SetOnFail)
|
||||
.CbFunc(_SC("BindExec"), &Listener::SetOnExec)
|
||||
.CbFunc(_SC("BindAuth"), &Listener::SetOnAuth)
|
||||
.CbFunc(_SC("BindPost"), &Listener::SetOnPost)
|
||||
.CbFunc(_SC("BindFail"), &Listener::SetOnFail)
|
||||
.Func(_SC("GetArgTag"), &Listener::GetArgTag)
|
||||
.FmtFunc(_SC("SetArgTag"), &Listener::SetArgTag)
|
||||
.Func(_SC("GetArgFlags"), &Listener::GetArgFlags)
|
||||
|
@ -626,22 +626,9 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the error callback.
|
||||
*/
|
||||
void SetOnFail(Object & env, Function & func)
|
||||
void SetOnFail(Function & func)
|
||||
{
|
||||
// Are we supposed to unbind current callback?
|
||||
if (func.IsNull())
|
||||
{
|
||||
m_OnFail.Release();
|
||||
}
|
||||
// Was there a custom environment specified?
|
||||
else if (env.IsNull())
|
||||
{
|
||||
m_OnFail = func;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_OnFail = Function(env.GetVM(), env.GetObj(), func.GetFunc());
|
||||
}
|
||||
m_OnFail = std::move(func);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -655,22 +642,9 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the authentication callback.
|
||||
*/
|
||||
void SetOnAuth(Object & env, Function & func)
|
||||
void SetOnAuth(Function & func)
|
||||
{
|
||||
// Are we supposed to unbind current callback?
|
||||
if (func.IsNull())
|
||||
{
|
||||
m_OnAuth.Release();
|
||||
}
|
||||
// Was there a custom environment specified?
|
||||
if (env.IsNull())
|
||||
{
|
||||
m_OnAuth = func;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_OnAuth = Function(env.GetVM(), env.GetObj(), func.GetFunc());
|
||||
}
|
||||
m_OnAuth = std::move(func);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -971,9 +945,9 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the error callback.
|
||||
*/
|
||||
void SetOnFail(Object & env, Function & func)
|
||||
void SetOnFail(Function & func)
|
||||
{
|
||||
GetValid()->SetOnFail(env, func);
|
||||
GetValid()->SetOnFail(func);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -987,9 +961,9 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the authentication callback.
|
||||
*/
|
||||
void SetOnAuth(Object & env, Function & func)
|
||||
void SetOnAuth(Function & func)
|
||||
{
|
||||
GetValid()->SetOnAuth(env, func);
|
||||
GetValid()->SetOnAuth(func);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1043,17 +1017,9 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process all command listeners with a function.
|
||||
*/
|
||||
void ForeachCommand(Object & env, Function & func) const
|
||||
void ForeachCommand(Function & func) const
|
||||
{
|
||||
if (env.IsNull())
|
||||
{
|
||||
GetValid()->ForeachCommand(func);
|
||||
}
|
||||
else
|
||||
{
|
||||
Function fn(env.GetVM(), env, func.GetFunc());
|
||||
GetValid()->ForeachCommand(fn);
|
||||
}
|
||||
GetValid()->ForeachCommand(func);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1747,22 +1713,9 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the function that must be called when this command listener is executed.
|
||||
*/
|
||||
void SetOnExec(Object & env, Function & func)
|
||||
void SetOnExec(Function & func)
|
||||
{
|
||||
// Are we supposed to unbind current callback?
|
||||
if (func.IsNull())
|
||||
{
|
||||
m_OnExec.Release();
|
||||
}
|
||||
// Was there a custom environment specified?
|
||||
else if (env.IsNull())
|
||||
{
|
||||
m_OnExec = func;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_OnExec = Function(env.GetVM(), env.GetObj(), func.GetFunc());
|
||||
}
|
||||
m_OnExec = std::move(func);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1776,22 +1729,9 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the function that must be called when this command listener needs to authenticate.
|
||||
*/
|
||||
void SetOnAuth(Object & env, Function & func)
|
||||
void SetOnAuth(Function & func)
|
||||
{
|
||||
// Are we supposed to unbind current callback?
|
||||
if (func.IsNull())
|
||||
{
|
||||
m_OnAuth.Release();
|
||||
}
|
||||
// Was there a custom environment specified?
|
||||
else if (env.IsNull())
|
||||
{
|
||||
m_OnAuth = func;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_OnAuth = Function(env.GetVM(), env.GetObj(), func.GetFunc());
|
||||
}
|
||||
m_OnAuth = std::move(func);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1805,22 +1745,9 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the function that must be called when this command listener finished execution.
|
||||
*/
|
||||
void SetOnPost(Object & env, Function & func)
|
||||
void SetOnPost(Function & func)
|
||||
{
|
||||
// Are we supposed to unbind current callback?
|
||||
if (func.IsNull())
|
||||
{
|
||||
m_OnPost.Release();
|
||||
}
|
||||
// Was there a custom environment specified?
|
||||
else if (env.IsNull())
|
||||
{
|
||||
m_OnPost = func;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_OnPost = Function(env.GetVM(), env.GetObj(), func.GetFunc());
|
||||
}
|
||||
m_OnPost = std::move(func);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1834,22 +1761,9 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the function that must be called when this command listener failed execution.
|
||||
*/
|
||||
void SetOnFail(Object & env, Function & func)
|
||||
void SetOnFail(Function & func)
|
||||
{
|
||||
// Are we supposed to unbind current callback?
|
||||
if (func.IsNull())
|
||||
{
|
||||
m_OnFail.Release();
|
||||
}
|
||||
// Was there a custom environment specified?
|
||||
else if (env.IsNull())
|
||||
{
|
||||
m_OnFail = func;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_OnFail = Function(env.GetVM(), env.GetObj(), func.GetFunc());
|
||||
}
|
||||
m_OnFail = std::move(func);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user