} // 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
} // func lines /// <summary></summary> /// <param name="file"></param> /// <returns></returns> public LuaResult close(LuaFile file = null) { if (file != null) { return(file.close()); } else if (defaultOutput != null) { LuaResult r = defaultOutput.close(); defaultOutput = null; return(r); } else { return(null); } } // proc close
} // 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
} // 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 = new LuaFile((string)file, "r"); 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
} // ctor public bool MoveNext() { if (file.IsClosed || file.TextReader.EndOfStream) { if (lCloseOnEnd) { file.close(); } return(false); } else { iReturnIndex++; if (returns == null || iReturnIndex >= returns.Length) // read returns { iReturnIndex = 0; returns = file.read(args); } return(true); } } // func MoveNext
} // ctor public bool MoveNext() { if (file.IsClosed) { if (closeOnEnd) { file.close(); } return(false); } else { returnIndex++; if (returns == null || returnIndex >= returns.Length) // read returns { returnIndex = 0; returns = file.read(args); } return(true); } } // func MoveNext
} // func lines /// <summary></summary> /// <param name="file"></param> /// <returns></returns> public LuaResult close(LuaFile file = null) { if (file != null) return file.close(); else if (defaultOutput != null) { LuaResult r = defaultOutput.close(); defaultOutput = null; return r; } else return null; } // proc close