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); } }
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())); }
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())); }
public static LuaValue Flush(LuaValue[] values) { return(FileLib.Flush(new LuaValue[] { Output(null) })); }