diff options
| author | jacob1 <jfu614@gmail.com> | 2013-05-03 19:09:35 (GMT) |
|---|---|---|
| committer | jacob1 <jfu614@gmail.com> | 2013-05-03 19:09:35 (GMT) |
| commit | e95e8e26bf0d11e33ef5f723abcd64348c0847fc (patch) | |
| tree | ebf58c4831fe4c7b434bea6cdb9d8541e9ecf9ae /src/cat/LuaScriptInterface.cpp | |
| parent | 2eaed9c9d478292f18d8a6aea9d2c9c869b26911 (diff) | |
| parent | 4cd12e8561b71ce32598d791ddedf5f1aef9203c (diff) | |
| download | powder-e95e8e26bf0d11e33ef5f723abcd64348c0847fc.zip powder-e95e8e26bf0d11e33ef5f723abcd64348c0847fc.tar.gz | |
Merge pull request #132 from mniip/lua2
Some lua fixes
Diffstat (limited to 'src/cat/LuaScriptInterface.cpp')
| -rw-r--r-- | src/cat/LuaScriptInterface.cpp | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index 74757e5..587be8c 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -57,6 +57,7 @@ Renderer * luacon_ren; bool *luacon_currentCommand; std::string *luacon_lastError; +std::string lastCode; int *lua_el_func, *lua_el_mode, *lua_gr_func; @@ -178,6 +179,8 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m): luacon_currentCommand = ¤tCommand; luacon_lastError = &lastError; + lastCode = ""; + //Replace print function with our screen logging thingy lua_pushcfunction(l, luatpt_log); lua_setglobal(l, "print"); @@ -2119,14 +2122,53 @@ int LuaScriptInterface::Command(std::string command) } else { - int ret; + int level = lua_gettop(l), ret; + std::string text = ""; lastError = ""; currentCommand = true; + if(lastCode.length()) + lastCode += "\n"; + lastCode += command; + std::string tmp = "return " + lastCode; ui::Engine::Ref().LastTick(clock()); - if((ret = luaL_dostring(l, command.c_str()))) + luaL_loadbuffer(l, tmp.c_str(), tmp.length(), "@console"); + if(lua_type(l, -1) != LUA_TFUNCTION) + { + lua_pop(l, 1); + luaL_loadbuffer(l, lastCode.c_str(), lastCode.length(), "@console"); + } + if(lua_type(l, -1) != LUA_TFUNCTION) { lastError = luacon_geterror(); - //Log(LogError, lastError); + if(std::string(lastError).find("near '<eof>'")!=-1) //the idea stolen from lua-5.1.5/lua.c + lastError = ">"; + else + lastCode = ""; + } + else + { + lastCode = ""; + ret = lua_pcall(l, 0, LUA_MULTRET, 0); + if(ret) + lastError = luacon_geterror(); + else + { + for(level++;level<=lua_gettop(l);level++) + { + luaL_tostring(l, level); + if(text.length()) + text += ", " + std::string(luaL_optstring(l, -1, "")); + else + text = std::string(luaL_optstring(l, -1, "")); + lua_pop(l, 1); + } + if(text.length()) + if(lastError.length()) + lastError += "; " + text; + else + lastError = text; + + } } currentCommand = false; return ret; |
