allow multiline code input, command will be executed when enough code given
This commit is contained in:
parent
0233d8db46
commit
4cd12e8561
@ -57,6 +57,7 @@ Renderer * luacon_ren;
|
|||||||
|
|
||||||
bool *luacon_currentCommand;
|
bool *luacon_currentCommand;
|
||||||
std::string *luacon_lastError;
|
std::string *luacon_lastError;
|
||||||
|
std::string lastCode;
|
||||||
|
|
||||||
int *lua_el_func, *lua_el_mode, *lua_gr_func;
|
int *lua_el_func, *lua_el_mode, *lua_gr_func;
|
||||||
|
|
||||||
@ -178,6 +179,8 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m):
|
|||||||
luacon_currentCommand = ¤tCommand;
|
luacon_currentCommand = ¤tCommand;
|
||||||
luacon_lastError = &lastError;
|
luacon_lastError = &lastError;
|
||||||
|
|
||||||
|
lastCode = "";
|
||||||
|
|
||||||
//Replace print function with our screen logging thingy
|
//Replace print function with our screen logging thingy
|
||||||
lua_pushcfunction(l, luatpt_log);
|
lua_pushcfunction(l, luatpt_log);
|
||||||
lua_setglobal(l, "print");
|
lua_setglobal(l, "print");
|
||||||
@ -2123,18 +2126,28 @@ int LuaScriptInterface::Command(std::string command)
|
|||||||
std::string text = "";
|
std::string text = "";
|
||||||
lastError = "";
|
lastError = "";
|
||||||
currentCommand = true;
|
currentCommand = true;
|
||||||
std::string tmp = "return " + command;
|
if(lastCode.length())
|
||||||
|
lastCode += "\n";
|
||||||
|
lastCode += command;
|
||||||
|
std::string tmp = "return " + lastCode;
|
||||||
ui::Engine::Ref().LastTick(clock());
|
ui::Engine::Ref().LastTick(clock());
|
||||||
luaL_loadbuffer(l, tmp.c_str(), tmp.length(), "@console");
|
luaL_loadbuffer(l, tmp.c_str(), tmp.length(), "@console");
|
||||||
if(lua_type(l, -1) != LUA_TFUNCTION)
|
if(lua_type(l, -1) != LUA_TFUNCTION)
|
||||||
{
|
{
|
||||||
lua_pop(l, 1);
|
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)
|
if(lua_type(l, -1) != LUA_TFUNCTION)
|
||||||
|
{
|
||||||
lastError = luacon_geterror();
|
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
|
else
|
||||||
{
|
{
|
||||||
|
lastCode = "";
|
||||||
ret = lua_pcall(l, 0, LUA_MULTRET, 0);
|
ret = lua_pcall(l, 0, LUA_MULTRET, 0);
|
||||||
if(ret)
|
if(ret)
|
||||||
lastError = luacon_geterror();
|
lastError = luacon_geterror();
|
||||||
|
Reference in New Issue
Block a user