summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2020-03-26 17:41:19 +0100
committerRobin Gareus <robin@gareus.org>2020-03-26 19:00:41 +0100
commit5a88a8d4a476d071550b98eec2219e0311962bbf (patch)
tree9b84f0d9a4270f21fbe3181daecb290e6397ac28
parent811dd0e6b49a380a6d13f4a4aab969c0fcc1e910 (diff)
Allow Lua-session to read and interpret scripts
-rw-r--r--tools/luadevel/luasession.cc103
1 files changed, 95 insertions, 8 deletions
diff --git a/tools/luadevel/luasession.cc b/tools/luadevel/luasession.cc
index e345fb750c..14bd9bd56a 100644
--- a/tools/luadevel/luasession.cc
+++ b/tools/luadevel/luasession.cc
@@ -1,5 +1,6 @@
-#include <stdint.h>
#include <assert.h>
+#include <getopt.h>
+#include <stdint.h>
#include <cstdio>
#include <iostream>
@@ -7,6 +8,13 @@
#include <list>
#include <vector>
+#ifdef PLATFORM_WINDOWS
+# include <io.h>
+# include <windows.h>
+#else
+# include <unistd.h>
+#endif
+
#include <glibmm.h>
#include "pbd/debug.h"
@@ -403,11 +411,9 @@ incomplete (lua_State* L, int status) {
return 0;
}
-int main (int argc, char **argv)
+static void
+interactive_interpreter ()
{
- init ();
- setup_lua ();
-
using_history ();
std::string histfile = Glib::build_filename (user_config_directory(), "/luahist");
@@ -459,6 +465,90 @@ int main (int argc, char **argv)
}
free (line);
printf ("\n");
+ write_history (histfile.c_str());
+}
+
+static bool
+is_tty ()
+{
+#ifdef PLATFORM_WINDOWS
+ return _isatty (_fileno (stdin));
+#else
+ return isatty (0);
+#endif
+}
+
+static void usage ()
+{
+ printf ("ardour-lua - interactive Ardour Lua interpreter.\n\n");
+ printf ("Usage: ardour-lua [ OPTIONS ] [ file ]\n\n");
+ printf ("Options:\n\
+ -h, --help display this help and exit\n\
+ -i, --interactive enter interactive mode after executing 'script'\n\
+ -V, --version print version information and exit\n\
+\n");
+ printf ("\n\
+Ardour at your finger tips...\n\
+\n");
+ printf ("Report bugs to <http://tracker.ardour.org/>\n"
+ "Website: <http://ardour.org/>\n");
+ ::exit (EXIT_SUCCESS);
+}
+
+int main (int argc, char **argv)
+{
+
+ const char *optstring = "hiV";
+
+ const struct option longopts[] = {
+ { "help", 0, 0, 'h' },
+ { "interactive", 0, 0, 'i' },
+ { "version", 0, 0, 'V' },
+ };
+
+ bool interactive = false;
+
+ int c = 0;
+ while (EOF != (c = getopt_long (argc, argv,
+ optstring, longopts, (int *) 0))) {
+ switch (c) {
+ case 'h':
+ usage ();
+ break;
+
+ case 'i':
+ interactive = true;
+ break;
+
+ case 'V':
+ printf ("ardour-lua version %s\n\n", VERSIONSTRING);
+ printf ("Copyright (C) GPL 2015-2020 Robin Gareus <robin@gareus.org>\n");
+ exit (EXIT_SUCCESS);
+ break;
+
+ default:
+ cerr << "Error: unrecognized option. See --help for usage information.\n";
+ ::exit (EXIT_FAILURE);
+ break;
+ }
+ }
+
+ init ();
+ setup_lua ();
+
+ if (argc > optind) {
+ lua->do_file (argv[optind]);
+ } else {
+ interactive = true;
+ }
+
+ if (!interactive || !keep_running) {
+ /* continue to exit */
+ } else if (is_tty ()) {
+ interactive_interpreter ();
+ } else {
+ luaL_dofile (lua->getState(), NULL);
+ }
if (session) {
close_session ();
@@ -469,12 +559,9 @@ int main (int argc, char **argv)
delete lua;
lua = NULL;
- write_history (histfile.c_str());
-
AudioEngine::instance ()->stop ();
AudioEngine::destroy ();
- // cleanup
ARDOUR::cleanup ();
delete event_loop;
pthread_cancel_all ();