Custom Code Block

holger krekel pyth at devel.trillke.net
Thu Jan 16 12:47:39 EST 2003


Zeev Hadar wrote:
> I would like to add my own custom code block as part of my python C++
> extension.
> 
> I'm using Python 2.2 version as a script language for my engine and I have
> wrote same python extensions in C++ for it.
> 
> I would like to add my own special code block that gives me control over the
> execution:
> 
> For example - python code:
> 
> def MyFunc():
>             x = 5
>             MySpecialBlock:
>                         x = x+1
>                         print x
>             print "func end"

i'll soon make something available where i introduced
quite exactly that.  For a complete patch look here

    http://codespeak.net/moin/moin.cgi/IndentedExecution

I have since cleaned it up but that is not published. 
Maybe you are lucky and my patch already heads in the same
direction you want to go.  Note though, that i don't think
you could package my patch with your C++ extension because
i modified the interpreter loop and added new bytecodes.
I am not 100% sure that you can achieve it without modifying 
the Python core short of hooking into __import__, rewriting
parts of the compiler and finding a way to express your protocol
with current bytecodes. 

> Where "MySpecialBlock" is coded in C++ as part of my python extension, and
> gives me control over the execution of its following code block.
> 
> I need to execute some actions before and after running this code block and
> control whether to run it or not at all.

My patch does 95% of that. The last 5% beeing that the object before
the block can currently not decide to skip the execution but that
would be easy.  Implementing the 'code block execution handler' in C++
is completly orthogonal to what i did.  If you know how to integrate C++
objects you can combine it with my patch.

> Please direct me for how to achieve it in Python extension.

feel free to ask more details,

    holger





More information about the Python-list mailing list