update runtime executable
This commit is contained in:
parent
7479bfd625
commit
cd8dfd7b69
1 changed files with 45 additions and 17 deletions
|
@ -14,45 +14,73 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
int main(int argc,const char** argv) {
|
||||
|
||||
argagg::parser argparser {{
|
||||
{ "help", {"-h", "--help"}, "shows this help message", 0},
|
||||
{ "file", {"-f", "--file"}, "load file to run", 1}
|
||||
}};
|
||||
}};
|
||||
|
||||
argagg::parser_results args;
|
||||
|
||||
std::ostringstream usage;
|
||||
usage
|
||||
<< "pixwerx rendering engine\n"
|
||||
<< '\n'
|
||||
<< "Usage: " << argv[0] << " [--help] [--file filename.lua]\n"
|
||||
<< '\n';
|
||||
|
||||
|
||||
try {
|
||||
|
||||
args = argparser.parse(argc,argv);
|
||||
|
||||
} catch (std::exception &e) {
|
||||
|
||||
std::cerr << e.what() << std::endl;
|
||||
|
||||
|
||||
argagg::fmt_ostream help(std::cerr);
|
||||
|
||||
help << usage.str() << argparser << '\n'
|
||||
<< "Encountered exception while parsing arguments: " << e.what()
|
||||
<< '\n';
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::ifstream input;
|
||||
|
||||
input.open(args["file"].as<std::string>(),std::ifstream::in);
|
||||
// run a file
|
||||
if (args["file"]) {
|
||||
|
||||
input.open(args["file"].as<std::string>(),std::ifstream::in);
|
||||
|
||||
if (!input.is_open()) {
|
||||
std::cerr << "cannot open '" << args["file"].as<std::string>() << "'" << std::endl;
|
||||
}
|
||||
|
||||
std::ostringstream sout;
|
||||
std::copy(std::istreambuf_iterator<char>(input),
|
||||
std::istreambuf_iterator<char>(),
|
||||
std::ostreambuf_iterator<char>(sout));
|
||||
|
||||
input.close();
|
||||
|
||||
pw::script::initialize();
|
||||
|
||||
pw::script s;
|
||||
|
||||
return s.eval(sout.str().c_str());
|
||||
|
||||
// show help
|
||||
} else if (args["help"]) {
|
||||
|
||||
argagg::fmt_ostream help(std::cerr);
|
||||
help << usage.str() << argparser;
|
||||
|
||||
if (!input.is_open()) {
|
||||
std::cerr << "cannot open '" << args["file"].as<std::string>() << "'" << std::endl;
|
||||
}
|
||||
|
||||
std::ostringstream sout;
|
||||
std::copy(std::istreambuf_iterator<char>(input),
|
||||
std::istreambuf_iterator<char>(),
|
||||
std::ostreambuf_iterator<char>(sout));
|
||||
|
||||
input.close();
|
||||
|
||||
pw::script::initialize();
|
||||
|
||||
pw::script s;
|
||||
|
||||
return s.eval(sout.str().c_str());
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue