Embedding a CPython Script engine in a .NET application.

C

Carl Waldbieser

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.AddNamedItem(Foo, "Foo")
'Load python script.
engine.LoadScript("D:\scripts\frotz.py")
'Run script (uses Foo).
engine.Run()
'Get results'
set resultsCollection = engine.getResults()

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.
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Carl said:
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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top