SetStreamFunctionRead Method (streamType, function)

SWI-Prolog SbsSW.SwiPlCs

Swi-cs-pl - A CSharp class library to connect .NET languages with SWI-Prolog SetStreamFunctionRead Method (streamType, function)
SwiPlCs interfaceSbsSW.SwiPlCsPlEngineSetStreamFunctionRead(PlStreamType, DelegateStreamReadFunction)
TODO
Declaration Syntax
C# Visual Basic Visual C++
public static void SetStreamFunctionRead(
	PlStreamType streamType,
	DelegateStreamReadFunction function
)
Public Shared Sub SetStreamFunctionRead ( _
	streamType As PlStreamType, _
	function As DelegateStreamReadFunction _
)
public:
static void SetStreamFunctionRead(
	PlStreamType streamType, 
	DelegateStreamReadFunction^ function
)
Parameters
streamType (PlStreamType)
Determine which stream to use PlStreamType
function (DelegateStreamReadFunction)
A DelegateStreamReadFunction
Examples
CopyC#
static string ref_string_read = "hello_dotnet_world_����.";     // The last 4 character are German umlauts.

static internal long Sread(IntPtr handle, System.IntPtr buffer, long buffersize)
{
    string s = ref_string_read + "\n";
    byte[] array = System.Text.Encoding.Unicode.GetBytes(s);
    System.Runtime.InteropServices.Marshal.Copy(array, 0, buffer, array.Length);
    return array.Length;
}


[TestMethod]
public void StreamRead()
{
    DelegateStreamReadFunction rf = new DelegateStreamReadFunction(Sread);
    PlEngine.SetStreamFunctionRead(PlStreamType.Input, rf);
    // NOTE: read/1 needs a dot ('.') at the end
    PlQuery.PlCall("assert( (test_read(A) :- read(A)) )");
    PlTerm t = PlQuery.PlCallQuery("test_read(A)");
    Assert.AreEqual(ref_string_read, t.ToString()+".");
}

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