Embedding a CPython Script engine in a .NET application.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Carl Waldbieser

    #1

    Embedding a CPython Script engine in a .NET application.

    Has anyone had any experience embedding a CPython engine in a .NET
    application? In the COM/ActiveX world, it was pretty easy to use Mark
    Hammond's win32 modules to create a script engine component that you could
    expose other COM objects to, but I was not sure how I would go about doing
    something similar in a .NET environment. For example, something like:

    .... .NET Application code ...
    'Create Foo object.
    set Foo = New Foo("baz")
    'Create embedded cpython script engine.
    set engine = New CPythonEngine()
    'Expose Foo object to engine.
    engine.AddNamed Item(Foo, "Foo")
    'Load python script.
    engine.LoadScri pt("D:\scripts\ frotz.py")
    'Run script (uses Foo).
    engine.Run()
    'Get results'
    set resultsCollecti on = engine.getResul ts()

    Is something like this possible, or am I thinking about things the wrong
    way?

    I am mainly interested in knowing if this is possible with cpython, as I
    understand IronPython is currently in beta.

    Thanks.

  • Martin v. Löwis

    #2
    Re: Embedding a CPython Script engine in a .NET application.

    Carl Waldbieser wrote:[color=blue]
    > Has anyone had any experience embedding a CPython engine in a .NET
    > application? In the COM/ActiveX world, it was pretty easy to use Mark
    > Hammond's win32 modules to create a script engine component that you could
    > expose other COM objects to, but I was not sure how I would go about doing
    > something similar in a .NET environment.[/color]

    I don't have experience with this specific problem, but in general,
    ..NET is really good at calling COM objects (in fact, this was
    historically the sole reason for creating .NET: to make COM better
    usable).

    So just import, in VS.NET, the Python interpreter to your project
    (Add Reference), and use the C# functions that the COM interop
    code gives you.

    Regards,
    Martin

    Comment

    Working...