summaryrefslogtreecommitdiff
path: root/i/marvin/src/interpreter/interpreter.cc
diff options
context:
space:
mode:
Diffstat (limited to 'i/marvin/src/interpreter/interpreter.cc')
-rw-r--r--i/marvin/src/interpreter/interpreter.cc36
1 files changed, 32 insertions, 4 deletions
diff --git a/i/marvin/src/interpreter/interpreter.cc b/i/marvin/src/interpreter/interpreter.cc
index bdc918a..0c067cf 100644
--- a/i/marvin/src/interpreter/interpreter.cc
+++ b/i/marvin/src/interpreter/interpreter.cc
@@ -30,15 +30,15 @@ Interpreter::~Interpreter (void)
{
for (Funcs::iterator i = funcs_.begin (); i != funcs_.end (); ++i)
{
- delete i->second;
+ delete i->second.func;
}
}
/// Add a function, Interpreter owns f.
void
-Interpreter::add (const std::string &s, Func *f)
+Interpreter::add (const std::string &s, Func *f, const std::string &desc)
{
- if (!funcs_.insert (Funcs::value_type (s, f)).second)
+ if (!funcs_.insert (Funcs::value_type (s, FuncDesc (f, desc))).second)
{
// Interpreter owns f, therefore, f must be deleted.
delete f;
@@ -47,6 +47,13 @@ Interpreter::add (const std::string &s, Func *f)
}
}
+/// Add a function without description, Interpreter owns f.
+void
+Interpreter::add (const std::string &s, Func *f)
+{
+ add (s, f, "");
+}
+
/// Call a function by name.
void
Interpreter::call (const std::string &s, const Args &a,
@@ -58,7 +65,7 @@ Interpreter::call (const std::string &s, const Args &a,
throw std::runtime_error ("function \'" + s + "\' does not exist");
try
{
- (*i->second) (a, dryrun);
+ (*i->second.func) (a, dryrun);
}
catch (const std::exception &e)
{
@@ -83,3 +90,24 @@ Interpreter::interpretFile (const std::string &file, bool dryrun/*false*/)
p.parseFile (file);
}
+/// Return an help string.
+std::string
+Interpreter::help (void) const
+{
+ std::string ret;
+ for (Funcs::const_iterator i = funcs_.begin (); i != funcs_.end (); ++i)
+ {
+ // Well, if you really want to implement this better, please do...
+ for (std::string::const_iterator j = i->second.desc.begin ();
+ j != i->second.desc.end (); j++)
+ {
+ if (*j == '\n')
+ ret += "\n ";
+ else
+ ret += *j;
+ }
+ ret += '\n';
+ }
+ return ret;
+}
+