SetStreamFunctionWrite Method (streamType, function)

SWI-Prolog SbsSW.SwiPlCs

Swi-cs-pl - A CSharp class library to connect .NET languages with SWI-Prolog SetStreamFunctionWrite Method (streamType, function)
SwiPlCs interfaceSbsSW.SwiPlCsPlEngineSetStreamFunctionWrite(PlStreamType, DelegateStreamWriteFunction)
This is a primitive approach to enter the output from a stream.
Declaration Syntax
C# Visual Basic Visual C++
public static void SetStreamFunctionWrite(
	PlStreamType streamType,
	DelegateStreamWriteFunction function
)
Public Shared Sub SetStreamFunctionWrite ( _
	streamType As PlStreamType, _
	function As DelegateStreamWriteFunction _
)
public:
static void SetStreamFunctionWrite(
	PlStreamType streamType, 
	DelegateStreamWriteFunction^ function
)
Parameters
streamType (PlStreamType)
Determine which stream to use PlStreamType
function (DelegateStreamWriteFunction)
A DelegateStreamWriteFunction
Examples
CopyC#
static string test_string;

static long Swrite(IntPtr handle, string buffer, long buffersize)
{
    string s = buffer.Substring(0, (int)buffersize);
    test_string = s;
    return buffersize;
}

[TestMethod]
public void StreamWrite()
{
    // NOTE: the Swrite function is only called if you flush the output or send a newline character
    string ref_string = "Hello .net world ����";        // The last 4 characters are German umlauts.
    PlQuery.PlCall("assert( (test_write :- writeln('" + ref_string + "'), flush_output) )");
    DelegateStreamWriteFunction wf = new DelegateStreamWriteFunction(Swrite);
    PlEngine.SetStreamFunctionWrite(PlStreamType.Output, wf);
    PlQuery.PlCall("test_write");
    Assert.AreEqual(ref_string+"\r\n", test_string);
}

Assembly: SwiPlCs (Module: SwiPlCs) Version: 1.1.60301.0 (1.1.60301.0)