mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-29 19:00:33 +02:00
print returned values; implicit return in console; console source
This commit is contained in:
@@ -664,7 +664,7 @@ void luacon_hook(lua_State * l, lua_Debug * ar)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int luaL_tostring (lua_State *L, int n) {
|
int luaL_tostring (lua_State *L, int n) {
|
||||||
luaL_checkany(L, n);
|
luaL_checkany(L, n);
|
||||||
switch (lua_type(L, n)) {
|
switch (lua_type(L, n)) {
|
||||||
case LUA_TNUMBER:
|
case LUA_TNUMBER:
|
||||||
|
@@ -9,6 +9,7 @@ extern Graphics * luacon_g;
|
|||||||
extern Renderer * luacon_ren;
|
extern Renderer * luacon_ren;
|
||||||
|
|
||||||
extern bool *luacon_currentCommand;
|
extern bool *luacon_currentCommand;
|
||||||
|
extern int luaL_tostring(lua_State* l, int n);
|
||||||
extern std::string *luacon_lastError;
|
extern std::string *luacon_lastError;
|
||||||
|
|
||||||
extern int *lua_el_func, *lua_el_mode, *lua_gr_func;
|
extern int *lua_el_func, *lua_el_mode, *lua_gr_func;
|
||||||
|
@@ -2119,14 +2119,43 @@ int LuaScriptInterface::Command(std::string command)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int ret;
|
int level = lua_gettop(l), ret;
|
||||||
|
std::string text = "";
|
||||||
lastError = "";
|
lastError = "";
|
||||||
currentCommand = true;
|
currentCommand = true;
|
||||||
|
std::string tmp = "return " + command;
|
||||||
ui::Engine::Ref().LastTick(clock());
|
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();
|
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;
|
currentCommand = false;
|
||||||
return ret;
|
return ret;
|
||||||
|
Reference in New Issue
Block a user