} // func open /// <summary></summary> /// <param name="args"></param> /// <returns></returns> public LuaResult lines(object[] args) { if (args == null || args.Length == 0) { return(defaultInput.lines(null)); } else { return(Lua.GetEnumIteratorResult(new LuaLinesEnumerator(LuaFileStream.OpenFile((string)args[0], "r", defaultEncoding), true, args, 1))); } } // func lines
/// <summary></summary> /// <param name="filename"></param> /// <param name="mode"></param> /// <returns></returns> public LuaResult open(string filename, string mode = "r") { try { return(new LuaResult(LuaFileStream.OpenFile(filename, mode, defaultEncoding))); } catch (Exception e) { return(new LuaResult(null, e.Message)); } } // func open
} // proc input /// <summary></summary> /// <param name="file"></param> /// <returns></returns> public LuaFile output(object file = null) { if (file is string) { defaultOutput?.close(); defaultOutput = LuaFileStream.OpenFile((string)file, "w", defaultEncoding); return(defaultOutput); } else if (file is LuaFile) { defaultOutput?.close(); defaultOutput = (LuaFile)file; } return(defaultOutput); } // proc output
} // proc close /// <summary></summary> /// <param name="file"></param> /// <returns></returns> public LuaFile input(object file = null) { if (file is string) { if (defaultInput != null) { defaultInput.close(); } defaultInput = LuaFileStream.OpenFile((string)file, "r", defaultEncoding); return(defaultInput); } else if (file is LuaFile) { if (defaultInput != null) { defaultInput.close(); } defaultInput = (LuaFile)file; } return(defaultInput); } // proc input
private static LuaFile InOutOpen(object file, Encoding defaultEncoding, ref LuaFile fileVar) { switch (file) { case string fileName: fileVar?.close(); fileVar = LuaFileStream.OpenFile(fileName, "w", defaultEncoding); break; case LuaFile handle: if (handle == defaultInOut.Value) { fileVar = null; } else { fileVar?.close(); fileVar = handle; } break; } return(fileVar ?? defaultInOut.Value); } // func InOutOpen