Skip to content

Commit

Permalink
added exit and reload commandline options; bumped to version 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
danomatika committed Oct 16, 2017
1 parent 566c1dd commit 08aa48b
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
@@ -1,3 +1,8 @@
1.2.0: 2017 Oct 16

* added -e/--exit commandline option to exit loaf after a script error
* added -r/--reload commandline option to reload loaf after a script error

1.1.0: 2017 Aug 9

* added --gl commandline option to set OpenGL version
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -105,6 +105,8 @@ Options:
-s, --start start listening for OSC messages
-f, --fullscreen start in fullscreen
-i, --ignore ignore script changes
-e, --exit exit after script error
-r, --reload reload timeout in secs after a script error
--gl open gl version ie. "4.1"
-v, --verbose verbose printing
Expand Down
7 changes: 7 additions & 0 deletions examples/tests/error.lua
@@ -0,0 +1,7 @@
-- error test
-- press any key to cause a script error

function keyPressed(key)
-- error: attempt to perform arithmetic on a nil value (global 'x')
local i = 1 + x
end
2 changes: 1 addition & 1 deletion openFrameworks-Info.plist
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<string>1.2.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
8 changes: 7 additions & 1 deletion src/CommandLine.cpp
Expand Up @@ -45,7 +45,9 @@ bool CommandLine::parse(int argc, char **argv) {
FULLSCREEN,
IGNORECHANGES,
VERBOSE,
OPENGL
OPENGL,
ERROREXIT,
ERRORRELOAD
};

// option and usage print descriptors
Expand All @@ -59,6 +61,8 @@ bool CommandLine::parse(int argc, char **argv) {
{STARTLISTENING, 0, "s", "start", Options::Arg::None, " -s, --start \tstart listening for OSC messages"},
{FULLSCREEN, 0, "f", "fullscreen", Options::Arg::None, " -f, --fullscreen \tstart in fullscreen"},
{IGNORECHANGES, 0, "i", "ignore", Options::Arg::None, " -i, --ignore \tignore script changes"},
{ERROREXIT, 0, "e", "exit", Options::Arg::None, " -e, --exit \texit after script error"},
{ERRORRELOAD, 0, "r", "reload", Options::Arg::Integer, " -r, --reload \treload timeout in secs after a script error"},
{OPENGL, 0, "", "gl", Options::Arg::NonEmpty, " --gl \topen gl version ie. \"4.1\""},
{VERBOSE, 0, "v", "verbose", Options::Arg::None, " -v, --verbose \tverbose printing"},
{UNKNOWN, 0, "", "", Options::Arg::Unknown, "\nArguments:"},
Expand Down Expand Up @@ -99,6 +103,8 @@ bool CommandLine::parse(int argc, char **argv) {
if(options.isSet(STARTLISTENING)) {startListening = true; changed = true;}
if(options.isSet(FULLSCREEN)) {fullscreen = true; changed = true;}
if(options.isSet(IGNORECHANGES)) {ignore = true; changed = true;}
if(options.isSet(ERROREXIT)) {errorExit = true; changed = true;}
if(options.isSet(ERRORRELOAD)) {errorReload = options.getInt(ERRORRELOAD); changed = true;}
if(options.isSet(OPENGL)) {opengl = options.getString(OPENGL); changed = true;}
if(options.isSet(VERBOSE)) {verbose = true; changed = true;}
return true;
Expand Down
2 changes: 2 additions & 0 deletions src/CommandLine.h
Expand Up @@ -43,6 +43,8 @@ class CommandLine {
bool startListening = false;
bool fullscreen = false;
bool ignoreChanges = false;
bool errorExit = false;
int errorReload = -1;
std::string opengl = "";
bool verbose = false;

Expand Down
10 changes: 10 additions & 0 deletions src/Script.cpp
Expand Up @@ -154,6 +154,10 @@ void Script::clear() {
//--------------------------------------------------------------
void Script::draw() {
if(error) {
if(errorReload > -1 && ofGetElapsedTimeMillis() - reloadTimestamp > errorReload) {
reload();
return;
}
ofPushView();
ofPushStyle();
ofSetRectMode(OF_RECTMODE_CORNER);
Expand Down Expand Up @@ -262,4 +266,10 @@ void Script::errorReceived(string& msg) {
error = true;
errorMsg.clear();
errorMsg = ofSplitString(msg, "\n");
if(errorExit) {
OF_EXIT_APP(1);
}
if(errorReload > -1) {
reloadTimestamp = ofGetElapsedTimeMillis();
}
}
16 changes: 12 additions & 4 deletions src/Script.h
Expand Up @@ -29,9 +29,18 @@ class ofxOscMessage;
class Script : protected ofxLuaListener {

public:

Script();


ofxLua lua; //< lua instance

/// num ms after script error before reloading automatically,
/// ignored if set to -1
int errorReload = -1;

/// exit the app on a script error? overrides errorReload if set
bool errorExit = false;

/// load a new script or folder with a main.lua file
/// clears the current lua state && sets script args if non-null
bool load(const string &path, const vector<string> *args=nullptr);
Expand Down Expand Up @@ -59,8 +68,6 @@ class Script : protected ofxLuaListener {
void setCurrentScript(string script) {currentScript = script;}
string getCurrentScript() {return currentScript;}

ofxLua lua; //< lua instance

/// returns true if a given path is a loadable script file
/// or directory with a main.lua script
static bool isLoadablePath(const string &path);
Expand All @@ -80,4 +87,5 @@ class Script : protected ofxLuaListener {
vector<string> arg; //< global "arg" table passed from commandline
bool error = false; //< is there an error?
vector<string> errorMsg; //< error message, separated by lines
long reloadTimestamp = 0; //< auto reload timestamp
};
2 changes: 2 additions & 0 deletions src/main.cpp
Expand Up @@ -41,6 +41,8 @@ int main(int argc, char *argv[]) {
options = nullptr;
}



// setup graphics
ofGLWindowSettings settings; // 1024, 576 for widescreen
settings.width = 640;
Expand Down
11 changes: 10 additions & 1 deletion src/ofApp.cpp
Expand Up @@ -56,6 +56,15 @@ void ofApp::setup() {
watch = false;
ofLogVerbose(PACKAGE) << "ignoring script changes";
}
if(options->errorExit) {
script.errorExit = options->errorExit;
ofLogVerbose(PACKAGE) << "exit after a script error";
}
else if(options->errorReload > -1) {
script.errorReload = options->errorReload * 1000; // s to ms
ofLogVerbose(PACKAGE) << "reload " << options->errorReload
<< "s after a script error";
}

// load script set via commandline
if(options->path != "") {
Expand Down Expand Up @@ -89,7 +98,7 @@ void ofApp::setup() {
if(watch) {
watcher.start();
}

// print current opengl version
ofLogVerbose(PACKAGE) << "open gl version: " << glGetString(GL_VERSION);

Expand Down

0 comments on commit 08aa48b

Please sign in to comment.