예제 #1
0
파일: main.cpp 프로젝트: aklofas/terra
void parse_args(lua_State * L, int  argc, char ** argv, bool * interactive, int * begin_script) {
    int ch;
    static struct option longopts[] = {
        { "help",      0,     NULL,           'h' },
        { "verbose",   0,     NULL,           'v' },
        { "interactive",     0,     NULL,     'i' },
        { "language", 1, NULL,                'l' },
        { NULL,        0,     NULL,            0 }
    };
    int verbose = 0;
    /*  Parse commandline options  */
    opterr = 0;
    while ((ch = getopt_long(argc, argv, "+hvil:", longopts, NULL)) != -1) {
        switch (ch) {
            case 'v':
                verbose++;
                terra_setverbose(L,verbose);
                break;
            case 'i':
                *interactive = true;
                break;
            case 'l':
                if(terra_loadfile(L,optarg) || lua_pcall(L,0,1,0) || terra_loadlanguage(L))
                  doerror(L);
                break;
            case ':':
            case 'h':
            default:
                usage();
                exit(-1);
                break;
        }
    }
    *begin_script = optind;
}
예제 #2
0
파일: main.cpp 프로젝트: Eddy1310/terra
void parse_args(lua_State * L, int  argc, char ** argv, bool * interactive, int * begin_script) {
    int ch;
    static struct option longopts[] = {
        { "help",      0,     NULL,           'h' },
        { "verbose",   0,     NULL,           'v' },
        { "interactive",     0,     NULL,     'i' },
        { "path",      0,     NULL,           'p' },
        { NULL,        0,     NULL,            0 }
    };
    int verbose = 0;
    /*  Parse commandline options  */
    opterr = 0;
    while ((ch = getopt_long(argc, argv, "+hvip:", longopts, NULL)) != -1) {
        switch (ch) {
        case 'v':
            verbose++;
            terra_setverbose(L,verbose);
            break;
        case 'i':
            *interactive = true;
            break;
        case 'p':
            lua_getglobal(L,"package");
            lua_getfield(L,-1,"path");
            lua_pushstring(L,";");
            lua_pushstring(L,optarg);
            lua_concat(L,3);
            lua_setfield(L,-2,"path");
            lua_pop(L,1);
            break;
        case ':':
        case 'h':
        default:
            usage();
            exit(-1);
            break;
        }
    }
    *begin_script = optind;
}