コード例 #1
0
        static int pmain(Lua.LuaState L)
        {
            Smain s    = (Smain)Lua.lua_touserdata(L, 1);
            int   argc = s.argc;

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

            if (Lua.lua_checkstack(L, argc) == 0)
            {
                fatal("too many input files");
            }
            for (i = 0; i < argc; i++)
            {
                Lua.CharPtr filename = (Lua.strcmp(argv[i], "-") == 0) ? null : argv[i];
                if (Lua.luaL_loadfile(L, filename) != 0)
                {
                    fatal(Lua.lua_tostring(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.lua_lock(L);
                Lua.luaU_dump(L, f, writer, D, stripping);
                Lua.lua_unlock(L);
                if (Lua.ferror(D) != 0)
                {
                    cannot("write");
                }
                if (Lua.fclose(D) != 0)
                {
                    cannot("close");
                }
            }
            return(0);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Hengle/SharpLua-1
        static int pmain(Lua.LuaState L)
        {
            Smain s    = (Smain)Lua.lua_touserdata(L, 1);
            int   argc = s.argc;

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

            if (Lua.lua_checkstack(L, argc) == 0)
            {
                fatal("too many input files");
            }
            for (i = 0; i < argc; i++)
            {
                Lua.CharPtr filename = (Lua.strcmp(argv[i], "-") == 0) ? null : argv[i];
                //try
                //{
                //    Lexer l = new Lexer();
                //    Parser p = new Parser(l.Lex(System.IO.File.ReadAllText(filename)));
                //    Ast.Chunk c = p.Parse();

                //Console.WriteLine(vars.Count);
                //foreach (Tuple<Ast.Variable, Ast.Variable> v in Refactoring.FindMisspelledVariables(c))
                //{
                //    Console.WriteLine("Warning: Possible misspelled variable: " + v.Item1.Name + " is close to " + v.Item2.Name);
                //    Console.Write("\t");
                //    if (v.Item1.References > v.Item2.References)
                //        Console.WriteLine(v.Item1.Name + " is the best match with" + v.Item1.References + " references");
                //    else if (v.Item1.References < v.Item2.References)
                //        Console.WriteLine(v.Item2.Name + " is the best match with" + v.Item2.References + " references");
                //    else
                //        Console.WriteLine("Both have the same amount of references (" + v.Item1.References + ")!");
                //
                //}
                //foreach (Ast.Variable v in Refactoring.FindUnusedVariables(c))
                //    Console.WriteLine("Warning: Unused variable '" + v.Name + "'");
                //Refactoring.FindReferencesBeforeDefinition(c);
                //}
                //catch (System.Exception ex)
                //{
                //    System.Diagnostics.Debug.WriteLine(ex.ToString());
                //}
                if (Lua.luaL_loadfile(L, filename) != 0)
                {
                    fatal(Lua.lua_tostring(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.lua_lock(L);
                Lua.luaU_dump(L, f, writer, D, stripping);
                Lua.lua_unlock(L);
                if (Lua.ferror(D) != 0)
                {
                    cannot("write");
                }
                if (Lua.fclose(D) != 0)
                {
                    cannot("close");
                }
            }
            return(0);
        }