/*
Copyright (C) 2015 Runtime Revolution Ltd.

This file is part of LiveCode.

LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.

LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with LiveCode.  If not see <http://www.gnu.org/licenses/>.  */

/*
This module specifies the syntax definitions and bindings for
stream input and output operations in modular LiveCode.
*/

module com.livecode.stream

public foreign type Stream binds to "kMCStreamTypeInfo"

--

public foreign handler MCStreamExecGetStandardOutput(out Stdout as Stream) returns nothing binds to "<builtin>"
public foreign handler MCStreamExecGetStandardError(out Stderr as Stream) returns nothing binds to "<builtin>"

/*
Summary:	Default output stream.
Returns:	The default output stream.

Description:
The default output stream for output from the program.

In command-line programs, this is usually used to output the results
of running the program.  In CGI programs running on servers, this is
usually used to output the data to be sent to the client.

Tags: IO
*/
syntax DefaultOutputStream is expression
	"the" "output" "stream"
begin
	MCStreamExecGetStandardOutput(output)
end syntax

/*
Summary:	Default error stream.
Returns:	The default error stream.

Description:
The default error stream for diagnostic information.

In command-line programs, this is usually used to display error
messages.  In server programs, data output through this stream may be
stored in the system log, depending on the server configuration.

Tags: IO
*/
syntax DefaultErrorStream is expression
	"the" "error" "stream"
begin
	MCStreamExecGetStandardError(output)
end syntax

--

public foreign handler MCStreamExecWriteToStream(in Buffer as Data, in Destination as Stream) returns nothing binds to "<builtin>"

/*
Summary:	Write data to a stream.

Buffer:	An expression that evaluates to binary data.
Stream:	An expression that evaluates to a stream.

Description:
Write some data to a stream.  If not all of the data can be written,
fails with an error.

>*Warning:* If the stream is able to accept only part of the data,
>some streams will write that part of the data and discard the rest.
>This may cause loss of data.


Tags: IO
*/
syntax WriteToStream is statement
	"write" <Buffer: Expression> "to" <Destination: Expression>
begin
	MCStreamExecWriteToStream(Buffer, Destination)
end syntax

--

end module
