static int pmain(lua_State *L) { struct Smain *s = &smain; char **argv = s->argv; int script; int flags = 0; globalL = L; if (argv[0] && argv[0][0]) progname = argv[0]; LUAJIT_VERSION_SYM(); /* linker-enforced version check */ script = collectargs(argv, &flags); if (script < 0) { /* invalid args? */ print_usage(); s->status = 1; return 0; } if ((flags & FLAGS_NOENV)) { lua_pushboolean(L, 1); lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV"); } lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ luaL_openlibs(L); /* open libraries */ s->status = tvm_loadbufferx(L, luaJIT_BC_op, luaJIT_BC_op_SIZE, "op", "b") || docall(L, 0, 1); if (s->status != 0) return 0; s->status = tvm_loadbufferx(L, luaJIT_BC_parse, luaJIT_BC_parse_SIZE, "parse", "b") || docall(L, 0, 1); if (s->status != 0) return 0; s->status = tvm_loadbufferx(L, luaJIT_BC_lunokhod, luaJIT_BC_lunokhod_SIZE, "lunokhod", "b") || docall(L, 0, 1); if (s->status != 0) return 0; lua_gc(L, LUA_GCRESTART, -1); if (!(flags & FLAGS_NOENV)) { s->status = handle_luainit(L); if (s->status != 0) return 0; } if ((flags & FLAGS_VERSION)) print_version(); s->status = runargs(L, argv, (script > 0) ? script : s->argc); if (s->status != 0) return 0; if (script) { s->status = handle_script(L, argv, script); if (s->status != 0) return 0; } if ((flags & FLAGS_INTERACTIVE)) { print_jit_status(L); dotty(L); } else if (script == 0 && !(flags & (FLAGS_EXEC|FLAGS_VERSION))) { if (lua_stdin_is_tty()) { print_version(); print_jit_status(L); dotty(L); } else { dofile(L, NULL); /* executes stdin as a file */ } } return 0; }
Datum _PG_init(PG_FUNCTION_ARGS) { int status; L = lua_open(); LUAJIT_VERSION_SYM(); lua_gc(L, LUA_GCSTOP, 0); luaL_openlibs(L); lua_gc(L, LUA_GCRESTART, -1); dolog("pglj_hook start"); lua_getglobal(L, "require"); lua_pushstring(L, "pglj_hook"); status = lua_pcall(L, 1, 1, 0); if (status) pg_throw("pglj_hook loading error"); lua_getfield(L, 1, "_PG_init"); init_ref = luaL_ref(L, LUA_REGISTRYINDEX); lua_getfield(L, 1, "_PG_fini"); fini_ref = luaL_ref(L, LUA_REGISTRYINDEX); lua_settop(L, 0); lua_rawgeti(L, LUA_REGISTRYINDEX, init_ref); status = lua_pcall(L, 0, 0, 0); if (status == 0){ PG_RETURN_VOID(); } if( status == LUA_ERRRUN) { pg_throw("%s %s","Error:",lua_tostring(L, -1)); } else if (status == LUA_ERRMEM) { pg_throw("%s %s","Memory error:",lua_tostring(L, -1)); } else if (status == LUA_ERRERR) { pg_throw("%s %s","Error:",lua_tostring(L, -1)); } pg_throw("pllj unknown error"); PG_RETURN_VOID(); }
static int pmain(lua_State *L) { struct Smain *s = (struct Smain *)lua_touserdata(L, 1); char **argv = s->argv; int script; int has_i = 0, has_v = 0, has_e = 0; globalL = L; if (argv[0] && argv[0][0]) progname = argv[0]; LUAJIT_VERSION_SYM(); /* linker-enforced version check */ lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ luaL_openlibs(L); /* open libraries */ lua_gc(L, LUA_GCRESTART, -1); s->status = handle_luainit(L); if (s->status != 0) return 0; script = collectargs(argv, &has_i, &has_v, &has_e); if (script < 0) { /* invalid args? */ print_usage(); s->status = 1; return 0; } if (has_v) print_version(); s->status = runargs(L, argv, (script > 0) ? script : s->argc); if (s->status != 0) return 0; if (script) s->status = handle_script(L, argv, script); if (s->status != 0) return 0; if (has_i) { print_jit_status(L); dotty(L); } else if (script == 0 && !has_e && !has_v) { if (lua_stdin_is_tty()) { print_version(); print_jit_status(L); dotty(L); } else { dofile(L, NULL); /* executes stdin as a file */ } } return 0; }
static int pmain(lua_State *L) { struct Smain *s = (struct Smain *)lua_touserdata(L, 1); char **argv = s->argv; int script; int flags = 0; globalL = L; if (argv[0] && argv[0][0]) progname = argv[0]; LUAJIT_VERSION_SYM(); /* linker-enforced version check */ script = collectargs(argv, &flags); if (script < 0) { /* invalid args? */ print_usage(); s->status = 1; return 0; } if ((flags & FLAGS_NOENV)) { lua_pushboolean(L, 1); lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV"); } lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ luaL_openlibs(L); /* open libraries */ /**************/ lua_pushstring(L, MULTIWIICL_VERSION); lua_setglobal(L, "MULTIWIICL_VERSION"); extern int luaopen_lpeg(lua_State*); lua_pushcfunction(L, luaopen_lpeg); lua_call(L, 0, 0); extern int luaopen_luaserial(lua_State*); lua_pushcfunction(L, luaopen_luaserial); lua_call(L, 0, 0); extern int luaopen_linenoise(lua_State*); lua_pushcfunction(L, luaopen_linenoise); lua_call(L, 0, 1); # include "Config.h" if (dostring(L, (const char*)Config, "@Config")) { printf("%s\n", lua_tostring(L, -1)); lua_pop(L, 1); } # include "MultiWii.h" if (dostring(L, (const char*)MultiWii, "@MultiWii")) { printf("%s\n", lua_tostring(L, -1)); lua_pop(L, 1); } /**************/ lua_gc(L, LUA_GCRESTART, -1); if (!(flags & FLAGS_NOENV)) { s->status = handle_luainit(L); if (s->status != 0) return 0; } s->status = runargs(L, argv, (script > 0) ? script : s->argc); if (s->status != 0) return 0; if (script) { s->status = handle_script(L, argv, script); if (s->status != 0) return 0; } if ((flags & FLAGS_INTERACTIVE) || (script == 0 && !(flags & (FLAGS_EXEC|FLAGS_VERSION)))) { # include "Prompt.h" if (dostring(L, (const char*)Prompt, "@Prompt")) { printf("%s\n", lua_tostring(L, -1)); lua_pop(L, 1); } } // if ((flags & FLAGS_VERSION)) print_version(); // s->status = runargs(L, argv, (script > 0) ? script : s->argc); // if (s->status != 0) return 0; // if (script) { // s->status = handle_script(L, argv, script); // if (s->status != 0) return 0; // } // if ((flags & FLAGS_INTERACTIVE)) { // print_jit_status(L); // dotty(L); // } else if (script == 0 && !(flags & (FLAGS_EXEC|FLAGS_VERSION))) { // if (lua_stdin_is_tty()) { // print_version(); // print_jit_status(L); // dotty(L); // } else { // dofile(L, NULL); /* executes stdin as a file */ // } // } return 0; }
static int pmain(lua_State *L) { struct Smain *s = &smain; char **argv = s->argv; int argn; int flags = 0; globalL = L; if (argv[0] && argv[0][0]) progname = argv[0]; LUAJIT_VERSION_SYM(); /* Linker-enforced version check. */ argn = collectargs(argv, &flags); if (argn < 0) { /* Invalid args? */ print_usage(); s->status = 1; return 0; } if ((flags & FLAGS_NOENV)) { lua_pushboolean(L, 1); lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV"); } /* Set MAD env _before_ libraries are open. */ mad_setenv(L, flags & FLAGS_NOENV); /* Stop collector during library initialization. */ lua_gc(L, LUA_GCSTOP, 0); luaL_openlibs(L); mad_openlibs(L); lua_gc(L, LUA_GCRESTART, -1); createargtable(L, argv, s->argc, argn); if (!(flags & FLAGS_NOENV)) { s->status = handle_luainit(L); if (s->status != LUA_OK) return 0; } /* MAD section. */ mad_setsig(); mad_regfunc(); if ((flags & FLAGS_MADENV)) dolibrary(L, "madl_main"); if (!(flags & FLAGS_NOENV)) { s->status = handle_madinit(L); if (s->status != LUA_OK) return 0; } if ((flags & FLAGS_VERSION)) print_version(); s->status = runargs(L, argv, argn); if (s->status != LUA_OK) return 0; if (s->argc > argn) { s->status = handle_script(L, argv + argn); if (s->status != LUA_OK) return 0; } if ((flags & FLAGS_INTERACTIVE)) { (void)print_jit_status; dotty(L); } else if (s->argc == argn && !(flags & FLAGS_EXEC)) { if (lua_stdin_is_tty()) { (void)print_version; (void)print_jit_status; dotty(L); } else { dofile(L, NULL); /* Executes stdin as a file. */ } } return 0; }