PlEngine Class

SWI-Prolog SbsSW.SwiPlCs

Swi-cs-pl - A CSharp class library to connect .NET languages with SWI-Prolog PlEngine Class
SwiPlCs interfaceSbsSW.SwiPlCsPlEngine
This static class represents the prolog engine.
Declaration Syntax
C# Visual Basic Visual C++
public static class PlEngine
Public NotInheritable Class PlEngine
public ref class PlEngine abstract sealed
Members
All Members Methods Properties



Icon Member Description
Initialize(array<String>[]()[][])

Initialise SWI-Prolog

The write method of the output stream is redirected to SbsSW.SwiPlCs.Streams before Initialize. The read method of the input stream just after Initialize.


IsInitialized
To test if the prolog engine is up.

PlCleanup()()()()
Try a clean up but it is buggy search the web for "possible regression from pl-5.4.7 to pl-5.6.27" to see reasons

PlHalt()()()()
Stops the PlEngine and the program

PlThreadAttachEngine()()()()

return : reference count of the engine

If an error occurs, -1 is returned.

If this Prolog is not compiled for multi-threading, -2 is returned.


PlThreadDestroyEngine()()()()
Returns TRUE on success and FALSE if the calling thread has no engine or this Prolog does not support threads.

PlThreadSelf()()()()
Returns the integer Prolog identifier of the engine or -1 if the calling thread has no Prolog engine. This method is also provided in the single-threaded version of SWI-Prolog, where it returns -2.

RegisterForeign(Delegate)

Register a C# callback method


RegisterForeign(String, Delegate)

Register a C# callback method


RegisterForeign(String, Int32, Delegate)

Register a C# callback method


RegisterForeign(String, String, Int32, Delegate)

Register a C# callback method


SetStreamFunctionRead(PlStreamType, DelegateStreamReadFunction)
TODO

SetStreamFunctionWrite(PlStreamType, DelegateStreamWriteFunction)
This is a primitive approach to enter the output from a stream.

Examples
A sample
CopyC#
if (!PlEngine.IsInitialized)
{
    String[] empty_param = { "" };
    PlEngine.Initialize(empty_param);
    // do some funny things ...
    PlEngine.PlCleanup();
} 
// program ends here
The following sample show how a file is consult via comand-line options.
CopyC#
public void Demo_consult_pl_file_by_param()
{
    string[] ref_values = { "gloria", "melanie", "ayala" };
    Console.WriteLine("Demo_consult_pl_file_by_param");

    // Build a prolog source file (skip this step if you already have one :-)
    string filename = Path.GetTempFileName();
    StreamWriter sw = File.CreateText(filename);
    sw.WriteLine("father(martin, inka).");
    sw.WriteLine("father(uwe, gloria).");
    sw.WriteLine("father(uwe, melanie).");
    sw.WriteLine("father(uwe, ayala).");
    sw.Close();

    // build the parameterstring to Initialize PlEngine with the generated file
    String[] param = { "-q", "-f", filename };
    try
    {
        PlEngine.Initialize(param);
        Console.WriteLine("all child's from uwe:");
        using (PlQuery q = new PlQuery("father(uwe, Child)"))
        {
            int idx = 0;
            foreach (PlQueryVariables v in q.SolutionVariables)
            {
                Console.WriteLine(v["Child"].ToString());
                Assert.AreEqual(ref_values[idx++], v["Child"].ToString());
            }
        }
    }
    catch (PlException e)
    {
        Console.WriteLine(e.MessagePl);
        Console.WriteLine(e.Message);
    }
    finally
    {
        PlEngine.PlCleanup();
    }
} // Demo_consult_pl_file_by_param
Inheritance Hierarchy
Object
PlEngine

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