X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FLog.cc;h=96c70955da1231d9d687260f75698ba5d9c74f74;hp=ddd12bbcd5a3dbec2e7bec2ee501e577058ebc59;hb=ca0f7bdfba63140dca0bd20586d31980f3938eb2;hpb=fdfba4553433b9b2804c2772c7645211b828c2ea diff --git a/src/Moof/Log.cc b/src/Moof/Log.cc index ddd12bb..96c7095 100644 --- a/src/Moof/Log.cc +++ b/src/Moof/Log.cc @@ -31,12 +31,13 @@ #include // strcpy #include "Log.hh" +#include "Script.hh" namespace Mf { -static LogLevel logLevel_ = WARNING; +static LogLevel logLevel_ = LOG_WARNING; inline void printLog_(int logLevel, const char* fmt, va_list args) { @@ -44,16 +45,19 @@ inline void printLog_(int logLevel, const char* fmt, va_list args) 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; } @@ -77,7 +81,7 @@ void logError(const char* fmt, ...) va_list args; va_start(args, fmt); - printLog_(ERROR, fmt, args); + printLog_(LOG_ERROR, fmt, args); va_end(args); } @@ -87,7 +91,7 @@ void logWarning(const char* fmt, ...) va_list args; va_start(args, fmt); - printLog_(WARNING, fmt, args); + printLog_(LOG_WARNING, fmt, args); va_end(args); } @@ -97,7 +101,7 @@ void logInfo(const char* fmt, ...) va_list args; va_start(args, fmt); - printLog_(INFO, fmt, args); + printLog_(LOG_INFO, fmt, args); va_end(args); } @@ -107,11 +111,61 @@ void logDebug(const char* fmt, ...) va_list args; va_start(args, fmt); - printLog_(DEBUGGING, fmt, args); + printLog_(LOG_DEBUG, fmt, args); + + va_end(args); +} + +static void logScript(const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + + 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