Example #1
0
        static int docall(LuaState L, int narg, int clear)
        {
            int status;
            int base_ = Lua.LuaGetTop(L) - narg;  /* function index */

            Lua.LuaPushCFunction(L, traceback);   /* push traceback function */
            Lua.LuaInsert(L, base_);              /* put it under chunk and args */
            //signal(SIGINT, laction);
            status = Lua.LuaPCall(L, narg, ((clear != 0) ? 0 : Lua.LUA_MULTRET), base_);
            //signal(SIGINT, SIG_DFL);
            Lua.LuaRemove(L, base_);              /* remove traceback function */
            /* force a complete garbage collection in case of errors */
            if (status != 0)
            {
                Lua.LuaGC(L, Lua.LUA_GCCOLLECT, 0);
            }
            return(status);
        }
Example #2
0
        static int pmain(LuaState L)
        {
            Smain s = (Smain)Lua.LuaToUserData(L, 1);

            string[] argv = s.argv;
            int      script;
            int      has_i = 0, has_v = 0, has_e = 0;

            globalL = L;
            if ((argv.Length > 0) && (argv[0] != ""))
            {
                progname = argv[0];
            }
            Lua.LuaGC(L, Lua.LUA_GCSTOP, 0);  /* stop collector during initialization */
            Lua.LuaLOpenLibs(L);              /* open libraries */
            Lua.LuaGC(L, Lua.LUA_GCRESTART, 0);
            s.status = handle_luainit(L);
            if (s.status != 0)
            {
                return(0);
            }
            script = collectargs(argv, ref has_i, ref has_v, ref has_e);
            if (script < 0)
            {              /* invalid args? */
                print_usage();
                s.status = 1;
                return(0);
            }
            if (has_v != 0)
            {
                print_version();
            }
            s.status = runargs(L, argv, (script > 0) ? script : s.argc);
            if (s.status != 0)
            {
                return(0);
            }
            if (script != 0)
            {
                s.status = handle_script(L, argv, script);
            }
            if (s.status != 0)
            {
                return(0);
            }
            if (has_i != 0)
            {
                dotty(L);
            }
            else if ((script == 0) && (has_e == 0) && (has_v == 0))
            {
                if (Lua.lua_stdin_is_tty() != 0)
                {
                    print_version();
                    dotty(L);
                }
                else
                {
                    dofile(L, null);                   /* executes stdin as a file */
                }
            }
            return(0);
        }