diff --git a/src/PowderToy.cpp b/src/PowderToy.cpp index 880aa7e05..abe234caf 100644 --- a/src/PowderToy.cpp +++ b/src/PowderToy.cpp @@ -73,7 +73,7 @@ SDL_Surface * SDLOpen() #endif SDL_WM_SetCaption("The Powder Toy", "Powder Toy"); - SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); atexit(SDL_Quit); return SDL_SetVideoMode(XRES + BARSIZE, YRES + MENUSIZE, 32, SDL_SWSURFACE); } diff --git a/src/cat/CommandInterface.cpp b/src/cat/CommandInterface.cpp index f146ed407..f434f540d 100644 --- a/src/cat/CommandInterface.cpp +++ b/src/cat/CommandInterface.cpp @@ -31,6 +31,11 @@ std::string CommandInterface::FormatCommand(std::string command) return command; } +void CommandInterface::Log(LogType type, std::string message) +{ + //Todo Put this info somewhere, an on-screen log output would be nice. +} + int CommandInterface::GetPropertyOffset(std::string key_, FormatType & format) { char * key = (char *)key_.c_str(); diff --git a/src/cat/CommandInterface.h b/src/cat/CommandInterface.h index 32b685e3c..c77d83c51 100644 --- a/src/cat/CommandInterface.h +++ b/src/cat/CommandInterface.h @@ -17,10 +17,12 @@ protected: std::string lastError; GameModel * m; public: + enum LogType { LogError, LogWarning, LogNotice }; enum FormatType { FormatInt, FormatString, FormatChar, FormatFloat }; CommandInterface(GameModel * m); int GetPropertyOffset(std::string key_, FormatType & format); int GetParticleType(std::string type); + void Log(LogType type, std::string message); //void AttachGameModel(GameModel * m); virtual void Tick() {} virtual int Command(std::string command); diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index f007a9f7a..c7af15577 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -80,6 +80,7 @@ LuaScriptInterface::LuaScriptInterface(GameModel * m): luacon_model = m; luacon_sim = m->GetSimulation(); luacon_g = ui::Engine::Ref().g; + luacon_ci = this; l = lua_open(); luaL_openlibs(l); @@ -211,71 +212,19 @@ void LuaScriptInterface::Tick() int LuaScriptInterface::Command(std::string command) { - luaL_dostring(l, command.c_str()); - return 0; + int ret; + lastError = ""; + if((ret = luaL_dostring(l, command.c_str()))) + { + lastError = luacon_geterror(); + Log(LogError, lastError); + } + return ret; } std::string LuaScriptInterface::FormatCommand(std::string command) { - //char ** keywords = {"and", "break", "do", "else", "elseif", "end", "false", "for", "function", "if", "in", "local", "nil", "not", "or", "repeat", "return", "then", "true", "until", "while", NULL}; - //char ** functions = {"_VERSION", "assert", "collectgarbage", "dofile", "error", "gcinfo", "loadfile", "loadstring", "print", "tonumber", "tostring", "type", "unpack", "_ALERT", "_ERRORMESSAGE", "_INPUT", "_PROMPT", "_OUTPUT", "_STDERR", "_STDIN", "_STDOUT", "call", "dostring", "foreach", "foreachi", "getn", "globals", "newtype", "rawget", "rawset", "require", "sort", "tinsert", "tremove", "_G", "getfenv", "getmetatable", "ipairs", "loadlib", "next", "pairs", "pcall", "rawegal", "rawget", "rawset", "require", "setfenv", "setmetatable", "xpcall", "string", "table", "math", "coroutine", "io", "os", "debug"}; - char * rawText = (char*)command.c_str(); - char * outputData = (char *)calloc(command.length()*6, 1); - char lastWord[command.length()]; - int lastWordChar = 0; - lastWord[0] = 0; - int rawTextLoc = 0; - int outputDataLoc = 0; - std::stack pstack; - while(rawText[rawTextLoc]) - { - switch(rawText[rawTextLoc]) - { - case '\\': - outputData[outputDataLoc++] = rawText[rawTextLoc++]; - if(rawText[rawTextLoc]) - outputData[outputDataLoc++] = rawText[rawTextLoc++]; - break; - case '"': - if(pstack.size() && pstack.top() == '"') - { - pstack.pop(); - outputData[outputDataLoc++] = rawText[rawTextLoc++]; - outputData[outputDataLoc++] = '\b'; - outputData[outputDataLoc++] = 'w'; - } - else - { - pstack.push('"'); - outputData[outputDataLoc++] = '\b'; - outputData[outputDataLoc++] = 'o'; - outputData[outputDataLoc++] = rawText[rawTextLoc++]; - } - break; - case '(': - pstack.push('('); - outputData[outputDataLoc++] = '\b'; - outputData[outputDataLoc++] = 't'; - strcpy(outputData+(outputDataLoc++), lastWord); - outputData[outputDataLoc++] = '\b'; - outputData[outputDataLoc++] = 'w'; - lastWord[0] = 0; - lastWordChar = 0; - break; - default: - if(pstack.top()!='"') - { - lastWord[lastWordChar++] = rawText[rawTextLoc++]; - lastWord[lastWordChar] = 0; - } - else - { - outputData[outputDataLoc++] = rawText[rawTextLoc++]; - } - break; - } - } - return outputData; + return command; } LuaScriptInterface::~LuaScriptInterface() { @@ -985,12 +934,7 @@ int luatpt_setconsole(lua_State* l) int luatpt_log(lua_State* l) { - /*char *buffer; - buffer = luaL_optstring(l, 1, ""); - strncpy(console_error, buffer, 254); - return 0;*/ - //luacon_ci->lastError = luaL_optstring(l, 1, ""); - //TODO IMPLEMENT - Have some sort of error log that is visible outside the console. + luacon_ci->Log(CommandInterface::LogNotice, luaL_optstring(l, 1, "")); return 0; }