public LuaArgs write(LuaArgs args) { int x = args.GetInt(0); int y = args.GetInt(1); if (args.IsNumber(2)) { var n = args.GetByte(2); CheckWritable(); if (x >= 0 && x < Image.Width && y >= 0 && y < Image.Height) { Image[x, y] = n; } return(LuaArgs.Empty); } else { var bytes = args.GetByteString(2); if (x < 0 || x >= Image.Width || y < 0 || y >= Image.Height || (x + y * Image.Width + bytes.Length) > Image.Width * Image.Height) { throw new LuaError("Write must start and end within the image bounds"); } CheckWritable(); Image.Write(bytes, 0, bytes.Length, x, y); return(LuaArgs.Empty); } }
public LuaArgs write(LuaArgs args) { if (args.IsNumber(1)) { int start = args.GetInt(0); var b = args.GetByte(1); if (start >= 0 && start < Buffer.Length) { Buffer[start] = b; } return(LuaArgs.Empty); } else { int start = args.GetInt(0); var bytes = args.GetByteString(1); if (start < 0 || start + bytes.Length > Buffer.Length) { throw new LuaError("Write must start and end within the buffer"); } Buffer.Write(start, bytes); return(LuaArgs.Empty); } }