예제 #1
0
 public static void ModOpen(IntPtr L)
 {
     Lua.Push(L => {
         string msg = Lua.ToString(L, 1);
         GMod.ConColorMsg(MsgCol, msg);
     });
     Lua.SetGlobal("Bullshit");
 }
예제 #2
0
        public void Print(IntPtr L, object F, params object[] O)
        {
            string S = F.ToString();

            if (O != null)
            {
                S = string.Format(S, O);
            }
            GMod.Print(S);
        }
예제 #3
0
        static void Main(string[] args)
        {
            IntPtr L = Lua.NewState();

            Lua.OpenLibs(L);
            Lua.AtPanic(L, (LL) => {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("\n\nPANIC!");
                Console.ResetColor();
                Console.WriteLine(Lua.ToString(LL, -1));
                Console.ReadKey();
                Environment.Exit(0);
                return(0);
            });
            GMod.Init(L);
            dynamic  G    = new LuaObject(L);
            Emulator Emul = new Emulator();

            FileSystemWatcher CSWatch = new FileSystemWatcher("script", "*.cs");

            CSWatch.Changed += (S, E) => {
                ExecFile(E.FullPath, L, G, Emul);
                Console.WriteLine(Prompt);
            };
            CSWatch.IncludeSubdirectories = true;
            CSWatch.EnableRaisingEvents   = true;

            string[] CSFiles = Directory.GetFiles("script", "*.cs");
            foreach (var CSFile in CSFiles)
            {
                ExecFile(CSFile, L, G, Emul);
            }

            if (File.Exists("script/autorun.lua"))
            {
                FileSystemWatcher FSW = new FileSystemWatcher("script", "autorun.lua");
                FSW.Changed += (S, E) => {
                    Console.Clear();
                    Lua.GetGlobal(L, "dofile");
                    Lua.PushString(L, "script/autorun.lua");
                    Emul.ErrorCheck(L, Lua.PCall(L, 1, 0, 0));
                    Console.Write(Prompt);
                };
                FSW.EnableRaisingEvents = true;

                Lua.GetGlobal(L, "dofile");
                Lua.PushString(L, "script/autorun.lua");
                Emul.ErrorCheck(L, Lua.PCall(L, 1, 0, 0));
            }

            while (true)
            {
                Console.Write(Prompt);
                if (!Emul.ErrorCheck(L, Lua.LoadString(L, Console.ReadLine())))
                {
                    try {
                        Emul.ErrorCheck(L, Lua.PCall(L, 0, 0, 0));
                    } catch (Exception E) {
                        Console.WriteLine("\n[{0}]\n{1}", E.GetType().Name, E.Message);
                    }
                }
            }
        }