예제 #1
0
        public static LuaValue open(LuaValue[] values)
        {
            LuaString file    = values[0] as LuaString;
            LuaString modeStr = values.Length > 1 ? values[1] as LuaString : null;
            string    mode    = modeStr == null ? "r" : modeStr.Text;

            switch (mode)
            {
            case "r":
            case "r+":
                StreamReader reader = File.OpenText(file.Text);
                return(new LuaUserdata(reader, FileLib.CreateMetaTable()));

            case "w":
            case "w+":
                StreamWriter writer = File.CreateText(file.Text);
                return(new LuaUserdata(writer, FileLib.CreateMetaTable()));

            case "a":
            case "a+":
                writer = File.AppendText(file.Text);
                return(new LuaUserdata(writer, FileLib.CreateMetaTable()));

            default:
                throw new ArgumentException("Invalid file open mode " + mode);
            }
        }
예제 #2
0
        public static LuaValue write(LuaValue[] values)
        {
            List <LuaValue> args = new List <LuaValue>(values.Length + 1);

            args.Add(output(null));
            args.AddRange(values);
            return(FileLib.write(args.ToArray()));
        }
예제 #3
0
        public static LuaValue read(LuaValue[] values)
        {
            List <LuaValue> args = new List <LuaValue>(values.Length + 1);

            args.Add(input(null));
            args.AddRange(values);
            return(FileLib.read(args.ToArray()));
        }
예제 #4
0
 public static LuaValue flush(LuaValue[] values)
 {
     return(FileLib.flush(new LuaValue[] { output(null) }));
 }