/**
  * pixwerx - a miniature 3D engine
  *
  * (c) Hartmut Seichter 2017-2018
  *
  */
#include <pw/core/core.hpp>
#include <pw/scripting/script.hpp>


#include <string>

#include <argagg/include/argagg/argagg.hpp>

#include <iostream>
#include <fstream>


//PW_RUNTIME_LUA_USE(core)


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;

    try {

        args = argparser.parse(argc,argv);

    } catch (std::exception &e) {

        std::cerr << e.what() << std::endl;

        return -1;
    }

    std::ifstream input;

    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());
}
