X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FLog.cc;h=96827e1a8be84a9219bbb47e1569f195af82f6eb;hp=dcdb5ecf5c205e3aea8f4ab32f6309cf4e04a64e;hb=892da43bf5796e7c5f593a6d0f53bd797a36bd3e;hpb=5fa5f117f28922a7e539a432367960c1a61f837d diff --git a/src/Moof/Log.cc b/src/Moof/Log.cc index dcdb5ec..96827e1 100644 --- a/src/Moof/Log.cc +++ b/src/Moof/Log.cc @@ -31,29 +31,33 @@ #include // strcpy #include "Log.hh" +#include "Script.hh" namespace Mf { -static LogLevel logLevel_ = WARNING; +static LogLevel logLevel_ = LOG_WARNING; -static void printLog_(int logLevel, const char* fmt, va_list args) +inline void printLog_(int logLevel, const char* fmt, va_list args) { if (logLevel_ < logLevel) return; switch (logLevel) { - case ERROR: + case LOG_ERROR: fprintf(stderr, " error: "); break; - case WARNING: + case LOG_WARNING: fprintf(stderr, "warning: "); break; - case INFO: + case LOG_SCRIPT: + fprintf(stderr, " script: "); + break; + case LOG_INFO: fprintf(stderr, " info: "); break; - case DEBUGGING: + case LOG_DEBUG: fprintf(stderr, " debug: "); break; } @@ -72,50 +76,96 @@ LogLevel setLogLevel(LogLevel level) } -void -logError(const char* fmt, ...) +void logError(const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + + printLog_(LOG_ERROR, fmt, args); + + va_end(args); +} + +void logWarning(const char* fmt, ...) { va_list args; va_start(args, fmt); - printLog_(ERROR, fmt, args); + printLog_(LOG_WARNING, fmt, args); va_end(args); } -void -logWarning(const char* fmt, ...) +void logInfo(const char* fmt, ...) { va_list args; va_start(args, fmt); - printLog_(WARNING, fmt, args); + printLog_(LOG_INFO, fmt, args); va_end(args); } -void -logInfo(const char* fmt, ...) +void logDebug(const char* fmt, ...) { va_list args; va_start(args, fmt); - printLog_(INFO, fmt, args); + printLog_(LOG_DEBUG, fmt, args); va_end(args); } -void -logDebug(const char* fmt, ...) +void logScript(const char* fmt, ...) { va_list args; va_start(args, fmt); - printLog_(DEBUGGING, fmt, args); + printLog_(LOG_SCRIPT, fmt, args); va_end(args); } +int logScript(Script& script) +{ + Script::Value param = script[1]; + + while (!param.isNone()) + { + if (param.isString()) + { + std::string str; + param.get(str); + logScript("%s", str.c_str()); + } + else if (param.isBoolean()) + { + if (param) logScript("true"); + else logScript("false"); + + } + else if (param.isNil()) + { + logScript("nil"); + } + else + { + logScript("%s (%X)", param.getTypeName().c_str(), + param.getIdentifier()); + } + + param.index++; + } + + return 0; +} + + +void importLogScript(Script& script) +{ + script.importFunction("print", (int (*)(Script&))logScript); +} + } // namespace Mf