Re: [IronPython] Multiple engine instances in IP 2.0 and beyond (was IronPython 2.0 Alpha 1 Released)

2007-05-02 Thread Kristof Wagemans
Is the following scenario supported in v2.0?

You have a Windows MDI application with two child windows open. Each window
contains a textbox and a label. No extra threads. No extra app domains.
You enter a command in the textbox on child window 1 and send it to the
engine for execution. The output of the command is displayed in the label on
window 1. Then you do the same thing for child window 2. Is the output of
the second command displayed in the label on window 2?


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Dino Viehland
Sent: Wednesday 2 May 2007 19:17
To: Discussion of IronPython
Subject: Re: [IronPython] Multiple engine instances in IP 2.0 and beyond
(was IronPython 2.0 Alpha 1 Released)

Thanks for the info...  Darn, it sounds like you actually want sys to be
isolated...

We're going to do a review over the hosting APIs internally next week.
That should result in the last large set of changes.  One thought that has
occurred to me is the ability to provide management of the current sys
instance.  This is where most of the state is tracked.  That would
presumably be something like allowing you to create a new system state and
provide the current system state at runtime.  You could then switch system
states before running a new script code.  In the multi-threaded case you
could store the system state in a thread local variable.  Therefore rather
than tracking a set of engines you'd track a list of SystemState objects (or
in DLR speak they may be some opaque state object).

The one interesting thing here is how this plays w/ console output.  In v2.0
that's separate from SystemState so you'd also need to update those at the
same time.

Any feedback on that proposal?


___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] System.Array

2006-09-08 Thread Kristof Wagemans








You can create an int array of length 3 with:

System.Array[int]((1,2,3))



Is there an alternative syntax to create an int array of
length 3 without passing in a tuple with 3 values? I know that I can create one
with:

System.Array.CreateInstance(int,3)








___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] System.Array

2006-09-08 Thread Kristof Wagemans








The question is: is there an alternative syntax
to create an array of a specific length. Now you have to go through a static
method of System.Array to create it.

I wanted to know if you can create it
directly and keep it looking like System.Array[int]. Something like: System.Array[int](3).
But this throws an exception.











From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of J. Merrill
Sent: Friday 8 September 2006
18:57
To: Discussion
 of IronPython
Subject: Re: [IronPython]
System.Array





Did you leave some part of your own question un-answered?
CreateInstance does just what you said you wanted to know how to do, doesn't
it?

At 04:22 AM 9/8/2006, Kristof Wagemans wrote



You can create an int array of length 3 with:
System.Array[int]((1,2,3))

Is
there an alternative syntax to create an int array of length 3 without passing
in a tuple with 3 values? I know that I can create one with:
System.Array.CreateInstance(int,3)







J. Merrill / Analytical Software Corp

___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Debugging support PythonEngine

2006-08-18 Thread Kristof Wagemans








Leaking memory with IronPython.Compiler.Options.GenerateDynamicMethods
= false isnt really a big issue: ClrDebuggingEnabled = true already
starts to leak memory (at least thats what the comment says).



Is there any complete documentation about
what actions cause memory leaks? By following this mailing list and looking at
the source code comments I know of some things, but Im sure that I dont
know all situations. Maybe it would be a good idea to have a setting
AllowMemoryLeaks which has a default of false. Whenever you go through a code
path that is going to leak memory through code generation you could throw an
exception. This way, you know at least that something youre doing is
wrong. If youre OK with the memory leak, then you could set AllowMemoryLeaks
to true. 











From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shri Borde
Sent: Thursday 17 August 2006
23:49
To: Discussion
 of IronPython
Subject: Re: [IronPython]
Debugging support PythonEngine





The first issue is
probably the same that IL offset 0 does not have any debug information.



Calling the delegate
add steps into a DynamicMethod which confuses VS. A workaround
for now is to add this statement before creating the PythonEngine.

IronPython.Compiler.Options.GenerateDynamicMethods
= false;

This disabled the
use of DynamicMethods altogether and will instead use AssemblyBuilder. This is
not generally recommended or supported since you are going to leak memory since
AssemblyBuilder memory cannot be reclaimed. However, VS seems to be better able
to deal with AssemblyBuilder during stepping, and it might be good enough for
you. This is a case where we will would need to teach the tool (VS) to handle
DynamicMethods differently than it currently does.










___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Debugging support PythonEngine

2006-08-17 Thread Kristof Wagemans








Its good to hear that its
fixable. But, off course, heres the next one J.





With the same little script:

x = 1

y = 2



def Add(a, b):

 x = a + b

 return x



z = Add(x, y)

print z





And the following C# code:

EngineOptions options = new
EngineOptions();

options.ClrDebuggingEnabled = true;

PythonEngine _pe = new
PythonEngine(options);



delegate int Add(int a, int b);



_pe.ExecuteFile(@ script
path );

Add add = _pe.EvaluateAsAdd(Add);

int var1 = add(2, 3);

int var2 = add(3, 4); 





The following happens:

(I use a release version of Ironpython
(RC2). There are no debug symbols present, so that I dont step into the
engine code.)

I step into ExecuteFile (F11) and get into
native code. After a few lines of native code, I can go back to the source code
view and Im in the Python script file. Maybe this is a similar issue as
with stepping into a function?

Next, I get a delegate to the Python Add
function. The first time I step into the add delegate I get the stepping into a
function problem and then Im inside the function. But, when I try to
step into the next add delegate this doesnt work anymore: the line is
marked in green in Visual Studio and I remain in the C# code. The next step
into command resumes on the next line in the C# code. I cant see a
reason why it would fail with the next add. Setting a breakpoint in the Python
function stops the execution at that point in both cases.











From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shri Borde
Sent: Thursday 17 August 2006
20:25
To: Discussion
 of IronPython
Subject: Re: [IronPython]
Debugging support PythonEngine



I have opened this
bug - http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPythonWorkItemId=2248
- to track the issue with stepping in. We are not emitting any line number
information for IL offset 0.










___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] PythonEngine.SetVariable

2006-08-17 Thread Kristof Wagemans
Now it has become:

   PythonEngine.Globals[myVar] = myVar;



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jon Cosby
Sent: Friday 18 August 2006 2:34
To: IronPython Users
Subject: [IronPython] PythonEngine.SetVariable

At one point, PythonEngine.SetVariable was replaced by
PythonEngine.SetGlobal. I don't find either of them in RC1. Why is this?


Jon

___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] pdb files

2006-08-12 Thread Kristof Wagemans








The .pdb files only contain information
for debugging an application. You do not need to redistribute them.











From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of jeff sacksteder
Sent: Saturday 12 August 2006 5:06
To: users@lists.ironpython.com
Subject: [IronPython] pdb files





I have compiled my application to an exe.

Must I distribute the .pdb files along with my app or can I just delete them?






___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Debugging support PythonEngine

2006-08-12 Thread Kristof Wagemans








Thanks for the info. Its good to
hear that there will be improvement possible in this area in the future. Although,
the way I interpret your explanation, its not going to be anytime soon (or
even this year), because you need enhancements to the underlying platform to
make this possible.



Ive experimented a bit with System.Diagnostics.DebuggerNonUserCodeAttribute
to see if it wasnt possible to skip stepping into IronPython code.
Unfortunately, the point where I get stuck in the assembly instructions is in
generated code. I dont understand this part of the code well enough to
know if its possible to make the debugger skip these lines. Maybe this
is why you need the changes to the platform?









From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shri Borde
Sent: Friday 11 August 2006 21:04
To: Discussion
 of IronPython
Subject: Re: [IronPython]
Debugging support PythonEngine





Yes, we will
definitely be working on improving the debugging support as it is a critical
part of the development process. However, full support will need work in
all parts of the tool chain including VS.



Python local
variables are implemented as normal MSIL variables (except in cases like
closures). Hence, VS is able to display them.



Currently, the best
way to debug Python functions in VS while using PythonEngine would be to enable
EngineOptions.ClrDebuggingEnable, open the PY file in VS and put a breakpoint where you want.
Stepping in and out of Python functions will step you through methods in
IronPython.dll .







From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kristof Wagemans
Sent: Friday, August 11, 2006
12:36 AM
To: 'Discussion
 of IronPython'
Subject: Re: [IronPython]
Debugging support PythonEngine







Are
there plans to improve the debugging experience in the future or are you at a
point where it is as good as it gets? Being able to debug makes
writing and using python scripts a lot easier.

Inside
functions I can see not only the function parameters but also the newly defined
local variables. Are these different from the global variables? I would have
expected that the function locals are also stored inside a dictionary.

Is it possible to step into python
functions without getting into assembly instructions? This is very frustrating
and degrades the debugging experience a lot. This is the more important issue
for me. Im not going to be using global variables frequently, but mostly
functions loaded in the PythonEngine that are called from C#.











From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shri Borde
Sent: Friday 11 August 2006 0:30
To: Discussion
 of IronPython
Cc: Glenn Hackney
Subject: Re: [IronPython]
Debugging support PythonEngine





If EngineOptions.ClrDebuggingEnabled
is set, we use AssemblyBuilder, TypeBuilder, etc for PythonEngine.Executed. The
code generated by AssemblyBuilder, TypeBuilder, etc supports PDB debug
information tracking for the methods, and so you will be able to set
breakpoints in the code. However, it does not guarantee a perfect debugging
experience. PythonEngine.ExecuteFile will use a dictionary for storing global
variables, and these will not be visible because VS does not know about the
dictionary. If you use PythonEngine.CreateOptimizedModule, most global
variables are implemented using CLR statics, and so VS may be able to display
them for you. Global variables added using an exec statement will still not be
visible.



If EngineOptions.ClrDebuggingEnabled
is false, we will use System.Reflection.Emit.DynamicMethod. This does not
support debug information tracking at all, and you will not even be able to see
function variables.



So If EngineOptions.ClrDebuggingEnabled
is will improve your debugging experience, but it wont give you a perfect
experience.





 

Do
you want to help develop Dynamic languages on CLR? (http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE-11F0-45DF-8B78-DC1B43134038)







From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kristof Wagemans
Sent: Thursday, August 10, 2006
2:10 PM
To: Discussion
 of IronPython
Subject: [IronPython] Debugging
support PythonEngine







I have been experimenting with the debugging support for the
PythonEngine. When I use the following code I have several problems.



PythonEngine _pe;

EngineOptions options = new EngineOptions();

options.ClrDebuggingEnabled = true;

_pe = new PythonEngine(options);

_pe.ExecuteFile(@ script );



Test script:



x = 1

y = 2



def Add(a, b):

 return a + b



z = Add(x, y)

print z





I opened the script file in Visual Studio and placed a
breakpoint at the beginning of the file. The application runs and breaks at the
correct location. Stepping through the lines works, but I cannot see any values
of the global variables.

When I try to step into the function I get a notification
that there is no source code available and I must show the disassembly. After I
step several times

Re: [IronPython] Debugging support PythonEngine

2006-08-11 Thread Kristof Wagemans








Are there plans to improve the debugging experience
in the future or are you at a point where it is as good as it gets?
Being able to debug makes writing and using python scripts a lot easier.



Inside functions I can see not only the
function parameters but also the newly defined local variables. Are these
different from the global variables? I would have expected that the function
locals are also stored inside a dictionary.



Is it possible to step into python
functions without getting into assembly instructions? This is very frustrating
and degrades the debugging experience a lot. This is the more important issue
for me. Im not going to be using global variables frequently, but mostly
functions loaded in the PythonEngine that are called from C#.











From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shri Borde
Sent: Friday 11 August 2006 0:30
To: Discussion
 of IronPython
Cc: Glenn Hackney
Subject: Re: [IronPython]
Debugging support PythonEngine





If EngineOptions.ClrDebuggingEnabled
is set, we use AssemblyBuilder, TypeBuilder, etc for PythonEngine.Executed. The
code generated by AssemblyBuilder, TypeBuilder, etc supports PDB debug
information tracking for the methods, and so you will be able to set
breakpoints in the code. However, it does not guarantee a perfect debugging
experience. PythonEngine.ExecuteFile will use a dictionary for storing global
variables, and these will not be visible because VS does not know about the
dictionary. If you use PythonEngine.CreateOptimizedModule, most global
variables are implemented using CLR statics, and so VS may be able to display
them for you. Global variables added using an exec statement will still not be
visible.



If EngineOptions.ClrDebuggingEnabled
is false, we will use System.Reflection.Emit.DynamicMethod. This does not
support debug information tracking at all, and you will not even be able to see
function variables.



So If EngineOptions.ClrDebuggingEnabled
is will improve your debugging experience, but it wont give you a perfect
experience.





 

Do
you want to help develop Dynamic languages on CLR? (http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE-11F0-45DF-8B78-DC1B43134038)







From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kristof Wagemans
Sent: Thursday, August 10, 2006
2:10 PM
To: Discussion
 of IronPython
Subject: [IronPython] Debugging
support PythonEngine







I have been experimenting with the debugging support for the
PythonEngine. When I use the following code I have several problems.



PythonEngine _pe;

EngineOptions options = new EngineOptions();

options.ClrDebuggingEnabled = true;

_pe = new PythonEngine(options);

_pe.ExecuteFile(@ script );



Test script:



x = 1

y = 2



def Add(a, b):

 return a + b



z = Add(x, y)

print z





I opened the script file in Visual Studio and placed a
breakpoint at the beginning of the file. The application runs and breaks at the
correct location. Stepping through the lines works, but I cannot see any values
of the global variables.

When I try to step into the function I get a notification
that there is no source code available and I must show the disassembly. After I
step several times through the assembly instructions I can return to the
original source code. Inside the function I can see the values of the function
variables.

I have tried debugging ipy.exe with the script and there I
can see the global variables, but I still have the problem with stepping into a
function. In ipy.exe the script file is executed in a different way. Using the
same method I can also see the global variables with my PythonEngine instance.
I apparently dont need to set ClrDebuggingEnabled in this case.



PythonEngine _pe;

_pe = new PythonEngine();

OptimizedEngineModule engineModule =
_pe.CreateOptimizedModule(@ script ,
__main__, true);

engineModule.Execute();



Are you required to use an OptimizedEngineModule to be able
to debug completely? Am I forgetting some settings for debugging? Can I step
directly into a function without getting into the assembly instructions?








___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] Debugging support PythonEngine

2006-08-10 Thread Kristof Wagemans








I have been experimenting with the debugging support for the
PythonEngine. When I use the following code I have several problems.



PythonEngine _pe;

EngineOptions options = new EngineOptions();

options.ClrDebuggingEnabled = true;

_pe = new PythonEngine(options);

_pe.ExecuteFile(@ script );



Test script:



x = 1

y = 2



def Add(a, b):

 return a + b



z = Add(x, y)

print z





I opened the script file in Visual Studio and placed a
breakpoint at the beginning of the file. The application runs and breaks at the
correct location. Stepping through the lines works, but I cannot see any values
of the global variables.

When I try to step into the function I get a notification that
there is no source code available and I must show the disassembly. After I step
several times through the assembly instructions I can return to the original source
code. Inside the function I can see the values of the function variables.

I have tried debugging ipy.exe with the script and there I
can see the global variables, but I still have the problem with stepping into a
function. In ipy.exe the script file is executed in a different way. Using the same
method I can also see the global variables with my PythonEngine instance. I apparently
dont need to set ClrDebuggingEnabled in this case.



PythonEngine _pe;

_pe = new PythonEngine();

OptimizedEngineModule engineModule =
_pe.CreateOptimizedModule(@ script ,
__main__, true);

engineModule.Execute();



Are you required to use an OptimizedEngineModule to be able
to debug completely? Am I forgetting some settings for debugging? Can I step
directly into a function without getting into the assembly instructions?








___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Embedding Question

2006-08-10 Thread Kristof Wagemans








Isnt engine.LoadAssembly(typeof(SomeAutoCadType).Assembly)
easier or is this different in some way?











From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dino Viehland
Sent: Thursday 10 August 2006
21:17
To: Discussion
 of IronPython
Subject: Re: [IronPython]
Embedding Question





Cool, looks like I
was only close though J You may have already imported clr into the default
module, but just for the record for those who havent youll need
an import clr there. I just realized I forgot it the 1st time,
and I had a redundant AddReference in the delegate call.
Im assuming you just fixed all that up, but just in case anyone
else needs to do something like this, heres the correct code:



delegate void AddReference(object assembly);

AddReference adr =
engine.CreateMethodAddReference(import
clr\nclr.AddReference(assembly));

adr(typeof(SomeAutoCadType).Assembly);








___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] PythonEngine.Import()

2006-07-29 Thread Kristof Wagemans








Is PythonEngine.Import() a hosting version of the python
import statement? It behaves differently and not all features of import are (yet?)
exposed.

 PythonEngine pe = new PythonEngine();

 pe.LoadAssembly(Assembly.GetAssembly(typeof(System.Data.DataSet)));

 pe.Execute(import
System.Data); // Adds System to pe.Globals. This is what
I would expect.

 pe.Import(System.Data);
// Adds Data to pe.Globals.



Is PythonEngine.LoadAssembly() a good name for the method? It
seems to behave more like clr.AddReferenceXYZ then clr.LoadAssemblyXYZ. Also, clr.LoadAssembly
loads and returns an assembly while PythonEngine.LoadAssembly() takes an assembly
as parameter and returns nothing.



The following code fails silently. Wouldnt it be
better to throw an ImportError exception?

 PythonEngine pe = new PythonEngine();

 pe.Import(DoesntExist);










___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] PythonEngine FilterStackFrame

2006-07-29 Thread Kristof Wagemans








There is a TODO comment in PythonEngine.cs to make the
public method FormatException private. I would find a simplified version of
this method really useful. You could use it to display an error message and remove
your own application from the call stack.



 public string FormatException(Exception
exception, FilterStackFrame filter)






___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] Debugging support PythonEngine

2006-07-27 Thread Kristof Wagemans








I have been experimenting with the debugging support for the
PythonEngine. When I use the following code I have several problems.



PythonEngine _pe;

EngineOptions options = new EngineOptions();

options.ClrDebuggingEnabled = true;

_pe = new PythonEngine(options);

_pe.ExecuteFile(@ script );





x = 1

y = 2



def Add(a, b):

 return a + b



z = Add(x, y)

print z





I opened the script file in Visual Studio and placed a
breakpoint at the beginning of the file. The application runs and breaks at the
correct location. Stepping through the lines works, but I cannot see any values
of variables.

When I try to step into the function I get a notification that
there is no source code available and I must show the disassembly. After I step
several times through the assembly I can return to the source code.

I have looked at debugging ipy.exe and there I can see the
variables, but I still have the problem with stepping into a function. In
ipy.exe the script file is executed in a different way. Using the same method I
can also see the variables. I apparently dont need to set ClrDebuggingEnabled.



PythonEngine _pe;

_pe = new PythonEngine();

OptimizedEngineModule engineModule =
_pe.CreateOptimizedModule(@ script ,
__main__, true);

engineModule.Execute();



Are you required to use an OptimizedEngineModule to be able
to debug? Am I forgetting some settings for debugging? Can I step directly into
a function without getting into the assembly?






___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] PythonEngine.EvaluateAs and future division

2006-07-26 Thread Kristof Wagemans








The following code gives different results. Is this expected
or a bug?



IronPython.Compiler.Options.Division =
IronPython.Compiler.DivisionOption.New;

PythonEngine _pe = new PythonEngine();

_pe.Execute(result1 = 1/2);

double result1 = Convert.ToDouble(_pe.Globals[result1]);

double result2 =
_pe.EvaluateAsdouble(1/2);



result1 = 0.5

result2 = 0.0






___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Python console control for WPF

2006-06-30 Thread Kristof Wagemans








I was actually thinking of System.Decimal.
I can now create one with Decimal(5), but it would be more convenient if I
could just add a single character or so to the number. You probably wouldnt
like extending the Python language for this, I would guess.











From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On
Behalf Of Dino Viehland
Sent: Friday 30 June 2006 18:03
To: Discussion of IronPython
Subject: Re: [IronPython] Python
console control for WPF





I think we can keep
FilterStackFrame public and like you suggest make it just take an Exception
object.



I think were
going to make the switch from SetGlobal taking a SymbolId to using a string,
but until we do that youre right to use SymbolTable.StringToId.



For double you
should ensure theres a decimal point in the number, or you could always
do float(1) which will give you the floating point version  although the
decimal point is preferred (in C# you can do 1D for this).



For Decimal are you
referring to System.Decimal or Pythons decimal type in the standard
library? I assume its the Python one, and I dont believe
theres any special syntax for that.











From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kristof Wagemans
Sent: Friday, June 30, 2006 7:06
AM
To: 'Discussion of IronPython'
Subject: Re: [IronPython] Python
console control for WPF







Thanks for the info about directly calling
a Python method. This is definitively going to be useful.



Maybe someone else has answers for my
other questions about FilterStackFrame, no overload with name for SetGlobal and
format specifiers for double and decimal?











From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On
Behalf Of Shri Borde
Sent: Wednesday 28 June 2006 0:05
To: Discussion of IronPython
Subject: Re: [IronPython] Python
console control for WPF





Hi Kristof,



You can call a Python method as such.



public delegate int IntIntDelegate(int arg);

engine.Execute(def IntIntMethod(a): return a *
100);

IntIntDelegate d = engine.EvaluateIntIntDelegate(IntIntMethod);



Console.WriteLine(d(2)); //
This prints 200





I have opened this bug http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPythonWorkItemId=632
to track the issue with setdefaultencoding.



Shri





 

Do
you want to help develop Dynamic languages on CLR? (http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE-11F0-45DF-8B78-DC1B43134038)











From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kristof Wagemans
Sent: Sunday, June 25, 2006 1:09
AM
To: users@lists.ironpython.com
Subject: [IronPython] Python
console control for WPF





Ive been experimenting with a Python console control
for WPF. The improvements made for IronPython beta 8 make this a lot easier
thanks to several new functions on the PythonEngine: ExecuteToConsole,
FormatException and ParseInteractiveInput.



One of the things I need to do to communicate with a C#
application is to change the default encoding to receive non-ascii characters.
For this I execute several commands after the PythonEngine instance is created.

 

 import sys

 sys.setdefaultencoding('utf_16_le')

 del(sys)



Setting the default encoding seems like a good candidate for
the options you can pass to the engine while creating a new instance. It would
also be easier if I could get at the options through a PythonEngine instance.



I hope youre not going to remove the FilterStackFrame
delegate from the FormatException method as the comment seems to indicate. I
think its very useful to filter my own C# application from the stack
trace. Maybe you could add an overload with just the Exception and
FilterStackFrame?



To set a variable in the PythonEngine you need to use
SetGlobal with a SymbolId. Am I correct to use SymbolTable.StringToId(name) to
generate a SymbolId? It used to be easier with just a string to specify the
name.



A useful enhancement for the PythonEngine might be if there
was a way to directly call a Python function loaded in the engine and pass
parameters to it and get the return value. You could also support out
parameters similar to calling a method through reflection.



If you want to specify that a number is a long you can write
10L. Is there a way to specify that a number is a double or a decimal?






___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] Python console control for WPF

2006-06-25 Thread Kristof Wagemans








Ive been experimenting with a Python console control
for WPF. The improvements made for IronPython beta 8 make this a lot easier
thanks to several new functions on the PythonEngine: ExecuteToConsole, FormatException
and ParseInteractiveInput.



One of the things I need to do to communicate with a C#
application is to change the default encoding to receive non-ascii characters. For
this I execute several commands after the PythonEngine instance is created.

 

 import sys

 sys.setdefaultencoding('utf_16_le')

 del(sys)



Setting the default encoding seems like a good candidate for
the options you can pass to the engine while creating a new instance. It would
also be easier if I could get at the options through a PythonEngine instance.



I hope youre not going to remove the FilterStackFrame
delegate from the FormatException method as the comment seems to indicate. I
think its very useful to filter my own C# application from the stack
trace. Maybe you could add an overload with just the Exception and
FilterStackFrame?



To set a variable in the PythonEngine you need to use SetGlobal
with a SymbolId. Am I correct to use SymbolTable.StringToId(name) to generate a
SymbolId? It used to be easier with just a string to specify the name.



A useful enhancement for the PythonEngine might be if there
was a way to directly call a Python function loaded in the engine and pass
parameters to it and get the return value. You could also support out
parameters similar to calling a method through reflection.



If you want to specify that a number is a long you can write
10L. Is there a way to specify that a number is a double or a decimal?






___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Are two PythonEngine instances connected?

2006-04-18 Thread Kristof Wagemans








I dont think that I would really require
multiple engine instances if I could use separated sessions (system states). I
could keep the states around and swap them in and out as required.



One possible problem: I create a new
session and run a script in it. This script triggers the execution of another
script. I would then need to unplug the current session, create a new session
and run the script inside it. After the second script finishes I need to put
the original session back and let it finish executing. I can imagine that it
would give problems to swap sessions while one was executing (although it was temporarily
suspended).



Using AppDomains or multiple Threads doesnt
seem like a workable solution. It would get very complex to make the data the
PythonEngine needs to operate on available in the other AppDomain. As for using
threads: multithreading and user interfaces dont work well together. (I
would have hoped that WPF fixed this problem, but alas)



I dont really need an immediate
solution for this. Im just experimenting now. I think that the scenario
that Ive outlined is an important use for IronPython: to integrate in a
.NET application and extend it with programmable and flexible extra functionality.








___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] Are two PythonEngine instances connected?

2006-04-16 Thread Kristof Wagemans








Ive created two PythonEngine instances and set the
Stdout for each instance to its own custom stream class (PythonStream) to
capture the output. This stream class takes a delegate to specify the function
to receive the response.



 class Tester

 {

 public void
Test()

 {


PythonEngine pythonEngine1 = new PythonEngine();


pythonEngine1.SetStdout(new PythonStream(ResponsePythonEngine1));




Console.WriteLine(pythonEngine1.Execute(\'p1'\) -
);


pythonEngine1.Execute('p1');


Console.WriteLine();




PythonEngine pythonEngine2 = new PythonEngine();

 pythonEngine2.SetStdout(new
PythonStream(ResponsePythonEngine2));




Console.WriteLine(pythonEngine2.Execute(\'p2'\) -
);


pythonEngine2.Execute('p2');


Console.WriteLine();




Console.WriteLine(pythonEngine1.Execute(\'p1'\) -
);


pythonEngine1.Execute('p1');


Console.WriteLine();




Console.ReadLine();

 }



 void
ResponsePythonEngine1(string text)

 {


if (!string.IsNullOrEmpty(text.Trim()))


{


Console.WriteLine( ResponsePythonEngine1 -  + text);


}

 }



 void
ResponsePythonEngine2(string text)

 {


if (!string.IsNullOrEmpty(text.Trim()))


{


Console.WriteLine( ResponsePythonEngine2 -  + text);


}

 }

 }





After pythonEngine2 is created I receive the responses from
commands executed on pythonEngine1 on the output of pythonEngine2.



pythonEngine1.Execute('p1') -

 ResponsePythonEngine1 - 'p1'



pythonEngine2.Execute('p2') -

 ResponsePythonEngine2 - 'p2'



pythonEngine1.Execute('p1') -

 ResponsePythonEngine2 - 'p1'





You can find my test application here:

http://users.telenet.be/kristof.wagemans/PythonEngineConnected.zip








___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] Bug with string encoding while redirecting to a custom stream

2006-04-03 Thread Kristof Wagemans








I needed to change the default ASCII encoding to Unicode because it
removed all accented characters when sending data to my custom stream. While
trying to get this to work I found the following problem.



Use PythonEngine.SetStdout(), PythonEngine.SetStderr(),
PythonEngine.SetStdin () to set your own custom stream. There is a PythonFile
wrapper created around the stream with the default encoding specified. Then
change the default encoding with sys.setdefaultencoding('utf_16_le'). The
encoding of the PythonFile remains the same and it keeps sending data in the
old format. I don't know how difficult it is to change this behavior and even
if it's possible to change the encoding dynamically.



An easy workaround for me is to change the default encoding first and
then set the new streams. I'm only using sys.setdefaultencoding('utf_16_le') to
specify the default encoding at startup of the PythonEngine. The setting that I
want to change is inaccessible: DefaultEncoding is an internal value in
SystemState. Maybe it would be a good idea to add this to the Options so that
it's possible to directly start the PythonEngine with the desired encoding. 



-



Something else: it would be nice if the __doc__ of enum's returned all
the names of the constants instead of 'no documentation available'.








___
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com