From 9d254a805ced77e551ecdbaaf076a9a90256950b Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Tue, 24 May 2016 18:45:50 +0300 Subject: [PATCH] Separate micellaneous functions. --- cbp/Module.cbp | 2 +- source/{Misc.cpp => CoreFuncs.cpp} | 48 ------------------------------ source/Logger.cpp | 45 ++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 49 deletions(-) rename source/{Misc.cpp => CoreFuncs.cpp} (70%) diff --git a/cbp/Module.cbp b/cbp/Module.cbp index b86d0de9..0c274901 100644 --- a/cbp/Module.cbp +++ b/cbp/Module.cbp @@ -450,6 +450,7 @@ + @@ -517,7 +518,6 @@ - diff --git a/source/Misc.cpp b/source/CoreFuncs.cpp similarity index 70% rename from source/Misc.cpp rename to source/CoreFuncs.cpp index d6e0389b..5253de0b 100644 --- a/source/Misc.cpp +++ b/source/CoreFuncs.cpp @@ -1,11 +1,7 @@ // ------------------------------------------------------------------------------------------------ #include "Core.hpp" -#include "Logger.hpp" #include "Base/Stack.hpp" -// ------------------------------------------------------------------------------------------------ -#include - // ------------------------------------------------------------------------------------------------ namespace SqMod { @@ -149,48 +145,4 @@ void Register_Core(HSQUIRRELVM vm) ); } -// ------------------------------------------------------------------------------------------------ -template < Uint8 L, bool S > static SQInteger LogBasicMessage(HSQUIRRELVM vm) -{ - const Int32 top = sq_gettop(vm); - // Was the message value specified? - if (top <= 1) - { - return sq_throwerror(vm, "Missing message value"); - } - // Attempt to generate the string value - StackStrF val(vm, 2); - // Have we failed to retrieve the string? - if (SQ_FAILED(val.mRes)) - { - return val.mRes; // Propagate the error! - } - // Forward the resulted string value to the logger - Logger::Get().Write(L, S, "%s", val.mPtr); - // This function does not return a value - return 0; -} - -// ================================================================================================ -void Register_Log(HSQUIRRELVM vm) -{ - RootTable(vm) - .Bind(_SC("SqLog"), Table(vm) - .SquirrelFunc(_SC("Dbg"), &LogBasicMessage< LOGL_DBG, false >) - .SquirrelFunc(_SC("Usr"), &LogBasicMessage< LOGL_USR, false >) - .SquirrelFunc(_SC("Scs"), &LogBasicMessage< LOGL_SCS, false >) - .SquirrelFunc(_SC("Inf"), &LogBasicMessage< LOGL_INF, false >) - .SquirrelFunc(_SC("Wrn"), &LogBasicMessage< LOGL_WRN, false >) - .SquirrelFunc(_SC("Err"), &LogBasicMessage< LOGL_ERR, false >) - .SquirrelFunc(_SC("Ftl"), &LogBasicMessage< LOGL_FTL, false >) - .SquirrelFunc(_SC("SDbg"), &LogBasicMessage< LOGL_DBG, true >) - .SquirrelFunc(_SC("SUsr"), &LogBasicMessage< LOGL_USR, true >) - .SquirrelFunc(_SC("SScs"), &LogBasicMessage< LOGL_SCS, true >) - .SquirrelFunc(_SC("SInf"), &LogBasicMessage< LOGL_INF, true >) - .SquirrelFunc(_SC("SWrn"), &LogBasicMessage< LOGL_WRN, true >) - .SquirrelFunc(_SC("SErr"), &LogBasicMessage< LOGL_ERR, true >) - .SquirrelFunc(_SC("SFtl"), &LogBasicMessage< LOGL_FTL, true >) - ); -} - } // Namespace:: SqMod diff --git a/source/Logger.cpp b/source/Logger.cpp index db752ae9..a94ac191 100644 --- a/source/Logger.cpp +++ b/source/Logger.cpp @@ -1,5 +1,6 @@ // ------------------------------------------------------------------------------------------------ #include "Logger.hpp" +#include "Base/Stack.hpp" // ------------------------------------------------------------------------------------------------ #include @@ -596,4 +597,48 @@ void OutputError(CCStr msg, ...) va_end(args); } +// ------------------------------------------------------------------------------------------------ +template < Uint8 L, bool S > static SQInteger LogBasicMessage(HSQUIRRELVM vm) +{ + const Int32 top = sq_gettop(vm); + // Was the message value specified? + if (top <= 1) + { + return sq_throwerror(vm, "Missing message value"); + } + // Attempt to generate the string value + StackStrF val(vm, 2); + // Have we failed to retrieve the string? + if (SQ_FAILED(val.mRes)) + { + return val.mRes; // Propagate the error! + } + // Forward the resulted string value to the logger + Logger::Get().Write(L, S, "%s", val.mPtr); + // This function does not return a value + return 0; +} + +// ================================================================================================ +void Register_Log(HSQUIRRELVM vm) +{ + RootTable(vm) + .Bind(_SC("SqLog"), Table(vm) + .SquirrelFunc(_SC("Dbg"), &LogBasicMessage< LOGL_DBG, false >) + .SquirrelFunc(_SC("Usr"), &LogBasicMessage< LOGL_USR, false >) + .SquirrelFunc(_SC("Scs"), &LogBasicMessage< LOGL_SCS, false >) + .SquirrelFunc(_SC("Inf"), &LogBasicMessage< LOGL_INF, false >) + .SquirrelFunc(_SC("Wrn"), &LogBasicMessage< LOGL_WRN, false >) + .SquirrelFunc(_SC("Err"), &LogBasicMessage< LOGL_ERR, false >) + .SquirrelFunc(_SC("Ftl"), &LogBasicMessage< LOGL_FTL, false >) + .SquirrelFunc(_SC("SDbg"), &LogBasicMessage< LOGL_DBG, true >) + .SquirrelFunc(_SC("SUsr"), &LogBasicMessage< LOGL_USR, true >) + .SquirrelFunc(_SC("SScs"), &LogBasicMessage< LOGL_SCS, true >) + .SquirrelFunc(_SC("SInf"), &LogBasicMessage< LOGL_INF, true >) + .SquirrelFunc(_SC("SWrn"), &LogBasicMessage< LOGL_WRN, true >) + .SquirrelFunc(_SC("SErr"), &LogBasicMessage< LOGL_ERR, true >) + .SquirrelFunc(_SC("SFtl"), &LogBasicMessage< LOGL_FTL, true >) + ); +} + } // Namespace:: SqMod