[IronPython] Python as embedded expression evaluator

Christian Schmidt Christian2.Schmidt at gmx.de
Tue Sep 18 14:47:39 PDT 2007


Hi all,

I'm using IronPython 1.1 as an expression evaluator in an C#
application. These expressions are evaluated repeatedly with different
variables. Therefore I should use CreateLambda instead of Evaluate. I
have the variables in an IDictionary<string, object>. But I don't know
what the CreateLambda equivalent of Evaluate(expression, module, locals)
is, where I hand over the variables in a dictionary.

Another question is, how I can determine the variables used by the
expression (dependencies). Is there an easy way, or do I have to use the
parser?

Furthermore I'd like to add functions to be available in expressions. By
adding objects to a module's globals property, I can access their
methods in an expression, but how can I add user defined C# functions
(public static) without the need to write the class name in front? For
example write Pow(a,b) instead of Math.Pow(a,b).

Is there a tutorial on how to use IronPython as an expression evaluator?
I'd be thankful for any hints on that topic.

Thanks,
Christian


More information about the Users mailing list