summaryrefslogtreecommitdiff
path: root/src/cat/LuaScriptInterface.cpp
diff options
context:
space:
mode:
authormniip <mniip@mniip.com>2013-05-03 05:56:13 (GMT)
committer mniip <mniip@mniip.com>2013-05-03 05:56:13 (GMT)
commit4cd12e8561b71ce32598d791ddedf5f1aef9203c (patch)
treeebf58c4831fe4c7b434bea6cdb9d8541e9ecf9ae /src/cat/LuaScriptInterface.cpp
parent0233d8db466c6ef402e5008671cfa6555a2d896d (diff)
downloadpowder-4cd12e8561b71ce32598d791ddedf5f1aef9203c.zip
powder-4cd12e8561b71ce32598d791ddedf5f1aef9203c.tar.gz
allow multiline code input, command will be executed when enough code given
Diffstat (limited to 'src/cat/LuaScriptInterface.cpp')
-rw-r--r--src/cat/LuaScriptInterface.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp
index 8d499a0..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 = &currentCommand;
luacon_lastError = &lastError;
+ lastCode = "";
+
//Replace print function with our screen logging thingy
lua_pushcfunction(l, luatpt_log);
lua_setglobal(l, "print");
@@ -2123,18 +2126,28 @@ int LuaScriptInterface::Command(std::string command)
std::string text = "";
lastError = "";
currentCommand = true;
- std::string tmp = "return " + command;
+ if(lastCode.length())
+ lastCode += "\n";
+ lastCode += command;
+ std::string tmp = "return " + lastCode;
ui::Engine::Ref().LastTick(clock());
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");
+ luaL_loadbuffer(l, lastCode.c_str(), lastCode.length(), "@console");
}
if(lua_type(l, -1) != LUA_TFUNCTION)
+ {
lastError = luacon_geterror();
+ 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();