From f8e845ebd2152c58a5395b5c5284ca384fc3ebcb Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Tue, 24 May 2016 07:29:35 +0300 Subject: [PATCH] Make the function environment optional in global callbacks. --- source/Core.cpp | 22 ++++++++++++++++++++++ source/CoreEntity.cpp | 17 ----------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/source/Core.cpp b/source/Core.cpp index e25522ca..98d5824c 100644 --- a/source/Core.cpp +++ b/source/Core.cpp @@ -525,6 +525,28 @@ void Core::CompilerErrorHandler(HSQUIRRELVM /*vm*/, CSStr desc, CSStr src, SQInt LogFtl("Message: %s\n[\n=>Location: %s\n=>Line: %d\n=>Column: %d\n]", desc, src, line, column); } +// ------------------------------------------------------------------------------------------------ +void Core::BindEvent(Int32 id, Object & env, Function & func) +{ + // Obtain the function instance called for this event + Function & event = GetEvent(id); + // Is the specified callback function null? + if (func.IsNull()) + { + event.Release(); // Then release the current callback + } + // Does this function need a custom environment? + else if (env.IsNull()) + { + event = func; + } + // Assign the specified environment and function + else + { + event = Function(env.GetVM(), env, func.GetFunc()); + } +} + // ------------------------------------------------------------------------------------------------ Core::BlipInst::~BlipInst() { diff --git a/source/CoreEntity.cpp b/source/CoreEntity.cpp index 8624716a..41aa92a5 100644 --- a/source/CoreEntity.cpp +++ b/source/CoreEntity.cpp @@ -860,23 +860,6 @@ bool Core::DelVehicle(Int32 id, Int32 header, Object & payload) return true; } -// ------------------------------------------------------------------------------------------------ -void Core::BindEvent(Int32 id, Object & env, Function & func) -{ - // Obtain the function instance called for this event - Function & event = GetEvent(id); - // Is the specified callback function null? - if (func.IsNull()) - { - event.Release(); // Then release the current callback - } - // Assign the specified environment and function - else - { - event = Function(env.GetVM(), env, func.GetFunc()); - } -} - // -------------------------------------------------------------------------------------------- void Core::ConnectPlayer(Int32 id, Int32 header, Object & payload) {