]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Log.cc
new level-based controllers
[chaz/yoink] / src / Moof / Log.cc
index ddd12bbcd5a3dbec2e7bec2ee501e577058ebc59..96827e1a8be84a9219bbb47e1569f195af82f6eb 100644 (file)
 #include <cstring>             // 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);
+}
+
+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
 
This page took 0.019403 seconds and 4 git commands to generate.