summaryrefslogtreecommitdiff
path: root/src/cat/LuaScriptInterface.cpp
diff options
context:
space:
mode:
authormniip <mniip@mniip.com>2013-05-02 21:54:21 (GMT)
committer mniip <mniip@mniip.com>2013-05-02 21:54:21 (GMT)
commit0233d8db466c6ef402e5008671cfa6555a2d896d (patch)
treeded1ec69a347315d7d09833334341599058be8cd /src/cat/LuaScriptInterface.cpp
parentd8023d21cd8240d4aedc9d63a0e1cd056b15c919 (diff)
downloadpowder-0233d8db466c6ef402e5008671cfa6555a2d896d.zip
powder-0233d8db466c6ef402e5008671cfa6555a2d896d.tar.gz
print returned values; implicit return in console; console source
Diffstat (limited to 'src/cat/LuaScriptInterface.cpp')
-rw-r--r--src/cat/LuaScriptInterface.cpp35
1 files changed, 32 insertions, 3 deletions
diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp
index 74757e5..8d499a0 100644
--- a/src/cat/LuaScriptInterface.cpp
+++ b/src/cat/LuaScriptInterface.cpp
@@ -2119,14 +2119,43 @@ int LuaScriptInterface::Command(std::string command)
}
else
{
- int ret;
+ int level = lua_gettop(l), ret;
+ std::string text = "";
lastError = "";
currentCommand = true;
+ std::string tmp = "return " + command;
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, command.c_str(), command.length(), "@console");
+ }
+ if(lua_type(l, -1) != LUA_TFUNCTION)
lastError = luacon_geterror();
- //Log(LogError, lastError);
+ else
+ {
+ 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;