Пример #1
0
        static int docall(Lua.LuaState L, int narg, int clear)
        {
            int status;
            int base_ = Lua.lua_gettop(L) - narg; /* function index */

            Lua.lua_pushcfunction(L, traceback);  /* push traceback function */
            Lua.lua_insert(L, base_);             /* put it under chunk and args */
            //signal(SIGINT, laction);
            status = Lua.lua_pcall(L, narg, ((clear != 0) ? 0 : Lua.LUA_MULTRET), base_);
            //signal(SIGINT, SIG_DFL);
            Lua.lua_remove(L, base_);  /* remove traceback function */
            /* force a complete garbage collection in case of errors */
            if (status != 0)
            {
                Lua.lua_gc(L, Lua.LUA_GCCOLLECT, 0);
            }
            return(status);
        }
Пример #2
0
        static int pmain(Lua.LuaState L)
        {
            Smain s = (Smain)Lua.lua_touserdata(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.lua_gc(L, Lua.LUA_GCSTOP, 0); /* stop collector during initialization */
            Lua.luaL_openlibs(L);             /* open libraries */
            Lua.lua_gc(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);
        }