예제 #1
0
        static int pmain(LuaState L)
        {
            Smain s    = (Smain)Lua.LuaToUserData(L, 1);
            int   argc = s.argc;

            string[]  argv = s.argv;
            Lua.Proto f;
            int       i;

            if (Lua.LuaCheckStack(L, argc) == 0)
            {
                fatal("too many input files");
            }
            for (i = 0; i < argc; i++)
            {
                CharPtr filename = (Lua.strcmp(argv[i], "-") == 0) ? null : argv[i];
                if (Lua.LuaLLoadFile(L, filename) != 0)
                {
                    fatal(Lua.LuaToString(L, -1));
                }
            }
            f = combine(L, argc);
            if (listing != 0)
            {
                Lua.luaU_print(f, (listing > 1)?1:0);
            }
            if (dumping != 0)
            {
                Stream D = (output == null) ? Lua.stdout : Lua.fopen(output, "wb");
                if (D == null)
                {
                    cannot("open");
                }
                Lua.LuaLock(L);
                Lua.LuaUDump(L, f, writer, D, stripping);
                Lua.LuaUnlock(L);
                if (Lua.ferror(D) != 0)
                {
                    cannot("write");
                }
                if (Lua.fclose(D) != 0)
                {
                    cannot("close");
                }
            }
            return(0);
        }
예제 #2
0
        static int handle_script(LuaState L, string[] argv, int n)
        {
            int     status;
            CharPtr fname;
            int     narg = getargs(L, argv, n);          /* collect arguments */

            Lua.LuaSetGlobal(L, "arg");
            fname = argv[n];
            if (Lua.strcmp(fname, "-") == 0 && Lua.strcmp(argv[n - 1], "--") != 0)
            {
                fname = null;                  /* stdin */
            }
            status = Lua.LuaLLoadFile(L, fname);
            Lua.LuaInsert(L, -(narg + 1));
            if (status == 0)
            {
                status = docall(L, narg, 0);
            }
            else
            {
                Lua.LuaPop(L, narg);
            }
            return(report(L, status));
        }
예제 #3
0
        static int dofile(LuaState L, CharPtr name)
        {
            int status = (Lua.LuaLLoadFile(L, name) != 0) || (docall(L, 0, 1) != 0) ? 1 : 0;

            return(report(L, status));
        }