views:

98

answers:

2

CodeContext is used throughout IronPython. But since I moved to IronPython RC1 I cannot get hold of one.

Has anyone used IronPython RC1 and managed to use

ClrModule.AddReferenceByName(...)

or

PythonType.__getattribute__(...)

Both of them take a CodeContext and hence I can no longer use them.

A: 

Just call these functions via 'eval' then.

leppie
It's an interesting idea and might work for the clr.AddRef piece. But I need to effectively reflect over python types from C# which I don't think would work well via eval() or Execute()
Jan Bannister
i am not sure how IronPython is laid out lately, but all modules (dlls) will have a static __global_context field. Else that failing, try using the InvariantContext, or try grab something from the ModuleContext.
leppie
Toplevel functions normally do not require a CodeContext as they contain no free variables, not sure why they have chosen this approach.
leppie
Thanks Leppie, Interesting ideas, I'll give it a go and see if it helps
Jan Bannister
Hope it works :)
leppie
+2  A: 

To get a hold of a CodeContext create a ModuleContext just like you used to craete a CodeContext. Then just access the GlobalContext property to get the CodeContext.

Dino Viehland
I did this. I built a ModuleContext and then built a CodeContext from it but I'm sure this is not the correct approach. I assume I should be getting the CodeContext from the CompiledCode which represents the code I'd like to run. I'll post more here once I get back round to this. In the mean time I've gone back to Beta 2
Jan Bannister