summaryrefslogtreecommitdiff
path: root/plugins/Dfusion
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-03-30 12:17:09 +0400
committerAlexander Gavrilov2012-03-30 12:17:09 +0400
commit063099e535feb02a4df2e0b89a746af1101871fb (patch)
treec67df6f16482dc68b686d7d3803e0643ff34255e /plugins/Dfusion
parente989ca58db10b644bfe1f05d7d2f851c4d943deb (diff)
downloaddfhack-063099e535feb02a4df2e0b89a746af1101871fb.tar.gz
dfhack-063099e535feb02a4df2e0b89a746af1101871fb.tar.bz2
dfhack-063099e535feb02a4df2e0b89a746af1101871fb.tar.xz
Set '_' to the first result value for both interactive shortcuts.
Makes it behave sort of like a general 'last result' reference.
Diffstat (limited to 'plugins/Dfusion')
-rw-r--r--plugins/Dfusion/dfusion.cpp31
1 files changed, 18 insertions, 13 deletions
diff --git a/plugins/Dfusion/dfusion.cpp b/plugins/Dfusion/dfusion.cpp
index a53bd45d..9a277fb4 100644
--- a/plugins/Dfusion/dfusion.cpp
+++ b/plugins/Dfusion/dfusion.cpp
@@ -120,10 +120,11 @@ void InterpreterLoop(color_ostream &out)
DFHack::CommandHistory hist;
lua::state s=lua::glua::Get();
string curline;
- out.print("Type quit to exit interactive mode.\n"
+ out.print("Type quit to exit interactive lua interpreter.\n"
"Shortcuts:\n"
" '= foo' => '_1,_2,... = foo'\n"
- " '! foo' => 'print(foo)'\n");
+ " '! foo' => 'print(foo)'\n"
+ "Both assign the first result to '_'\n");
assert(out.is_console());
Console &con = static_cast<Console&>(out);
int vcnt = 1;
@@ -142,7 +143,9 @@ void InterpreterLoop(color_ostream &out)
try
{
- if (curline[0] == '=')
+ char pfix = curline[0];
+
+ if (pfix == '=' || pfix == '!')
{
curline = "return " + curline.substr(1);
@@ -150,14 +153,22 @@ void InterpreterLoop(color_ostream &out)
s.pcall(0, LUA_MULTRET);
int numret = s.gettop();
- for (int i = 1; i <= numret; i++)
+ if (numret >= 1)
{
- if (i == 1)
+ s.pushvalue(1);
+ s.setglobal("_");
+
+ if (pfix == '!')
{
- s.pushvalue(i);
- s.setglobal("_");
+ s.getglobal("print");
+ s.insert(1);
+ s.pcall(numret,0);
+ numret = 0;
}
+ }
+ for (int i = 1; i <= numret; i++)
+ {
std::string name = stl_sprintf("_%d", vcnt++);
s.pushvalue(i);
s.setglobal(name);
@@ -168,12 +179,6 @@ void InterpreterLoop(color_ostream &out)
s.pcall(1,0);
}
}
- else if (curline[0] == '!')
- {
- curline = "print(" + curline.substr(1) + ")";
- s.loadstring(curline);
- s.pcall();
- }
else
{
s.loadstring(curline);