KOBRA 2.0 - .NET for Python (now supports CALLBACKS!)

Chetan Gadgil cgjunkaddr at attbi.com
Wed Feb 12 00:40:55 EST 2003


Thanks to all for your support.

I finally managed to get basic callback support working. I had thought it
would be much much simpler than calling .NET from Python. Well, it is;
however, due to some quirks in the way my library is implemented and how
.NET reflection works, I had to struggle a lot.

As a result, for now, I only have simple types supported in callbacks,
(complex type support coming soon).

In any case, one can very nicely abstract out the Delegate model in .NET
with a simple support class and a little bit of coding overhead.

I am currently prepping my code (removing lot of junk experimental code) to
submit to sourceforge.net. It is going to be opensource.


http://www.gadgil.net/DotNetWrapperForPython.htm


Direct DOWNLOAD LINK:
http://www.gadgil.net/files/kobralib-2.0.win32.exe


Example:


Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import kobralib
kobra - A Python Wrapper for .NET
Copyright (C) 2003 Chetan Gadgil (chetan at gadgil dot net)
All Rights Reserved
>>> def foo(x):
...     print "OK"
...     return x*x
...     print "OK"
...
>>> xx = kobralib.createObject("PythonCallerLib.dll",
"PythonCallerLib.PyCallableObject", foo)
callable Object!
>>> xx.callMethod([2.3])
OK
5.2899999999999991
>>>

Here:
xx.callMethod([2.3])

will call the above method with "2.3" as the arg. Multiple args are
supported; however only strings, long/int, floats are supported. I am being
a bit lazy about complex type support.


If you want to use with delegates:

Create a wrapper .NET class (in C# or VB.NET or any other language):
1) import PythonCallerLib.dll
2) Have a method in the delegate object to set the
PythonCallerLib.PyCallableObject
3) Whenever the delegate is invoked, call "callMethod" on this obj with
required args.
4) Python return value will be translated/sent back to .NET


I think this is a significant milestone. Now we need to build the Python
wrapper a bit more to hide the idiosyncrasies/complexities of the .NET DLL
layer.

Regards
Chetan Gadgil
(Public address: cgjunkaddr at attbi.com)






More information about the Python-list mailing list