int main(int argc, char ** argv) { progname = argv[0]; lua_State * L = luaL_newstate(); luaL_openlibs(L); if(terra_init(L)) doerror(L); bool interactive = false; int scriptidx; parse_args(L,argc,argv,&interactive,&scriptidx); if(scriptidx < argc) { int narg = getargs(L, argv, scriptidx); lua_setglobal(L, "arg"); if(terra_loadfile(L,argv[scriptidx])) doerror(L); lua_insert(L, -(narg + 1)); if(lua_pcall(L, narg, LUA_MULTRET, 0)) doerror(L); } if(isatty(0) && (interactive || scriptidx == argc)) { progname = NULL; dotty(L); } printstats(L); return 0; }
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; }
int terra_lualoadfile(lua_State * L) { const char * file = NULL; if(lua_gettop(L) > 0) file = luaL_checkstring(L,-1); if(terra_loadfile(L,file)) { lua_pushnil(L); lua_pushvalue(L,-2); lua_remove(L,-3); return 2; } return 1; }
int load_launchscript( lua_State * L, ebb_Options * ebboptions ) { char * bindir = getexec_dirpath(); if(!bindir) { errquit(L, "ERROR: Failed to retreive path to this executable.\n"); } char buffer[MAX_PATH_LEN]; // plenty of room size_t bufsize = MAX_PATH_LEN; if (ebboptions->uselegion) { snprintf(buffer, bufsize, "%s/../include/ebb/src/launch_legion.t", bindir); } else { snprintf(buffer, bufsize, "%s/../include/ebb/src/launch_script.t", bindir); } return terra_loadfile(L,buffer); }
int main(int argc, char ** argv) { progname = argv[0]; lua_State * L = luaL_newstate(); luaL_openlibs(L); terra_Options options; memset(&options, 0, sizeof(terra_Options)); bool interactive = false; int scriptidx; parse_args(L,argc,argv,&options,&interactive,&scriptidx); if(terra_initwithoptions(L, &options)) doerror(L); setupsigsegv(L); if(scriptidx < argc) { int narg = getargs(L, argv, scriptidx); lua_setglobal(L, "arg"); const char * filename = argv[scriptidx]; if(!strcmp(filename,"-")) filename = NULL; if(terra_loadfile(L,filename)) doerror(L); lua_insert(L, -(narg + 1)); if(lua_pcall(L, narg, LUA_MULTRET, 0)) doerror(L); } if(isatty(0) && (interactive || scriptidx == argc)) { progname = NULL; dotty(L); } lua_close(L); terra_llvmshutdown(); return 0; }