Hosting Cobra in VB.NET or C#
Posted:
Sat Nov 19, 2011 12:05 pm
by Stugol
Hi. Python and Ruby can be hosted in VB or C# like this:
- Code: Select all
Imports Microsoft.Scripting, IronPython.Hosting
Dim pyEngine = IronPython.Hosting.Python.CreateEngine
Dim ScriptSource = pyEngine.CreateScriptSourceFromString("...some code...", SourceCodeKind.Statements)
ScriptSource.Execute()
Is there any way to do the same with Cobra? I'd like to run Cobra scripts on the fly in my own software.
Re: Hosting Cobra in VB.NET or C#
Posted:
Sun Nov 20, 2011 3:33 am
by Charles
I set Cobra up to provide a library containing the compiler, but it apparently broke at some point as I discovered the last time I went to use it. It's on my list to fix.
Re: Hosting Cobra in VB.NET or C#
Posted:
Sun Nov 20, 2011 7:20 am
by Stugol
Hmm. When .NET languages are compiled on the fly using the CodeDom, they take a few seconds to compile; and utilise temp files on the system and stuff like that. It's quite a heavyweight operation, and not really suitable for quick scripts. When IronPython and IronRuby are compiled on the fly, in the way I showed you, they execute immediately with no system impact. They are, in essence, scripting languages.
So, my questions are these. Firstly, when Cobra is hosted in this manner (which, as you say, doesn't currently work), how will it be done? Like Python, or like .NET? Is it a heavyweight operation, or a quick one suited to scripting?
Secondly, assuming it is a lightweight operation, how soon could we expect this facility to work properly? (If it is a heavyweight operation, then I'll just carry on using Python for my in-app scripting.)
Re: Hosting Cobra in VB.NET or C#
Posted:
Sun Nov 20, 2011 11:42 am
by Charles
I'm sorry to report that currently it is a heavyweight operation, primarily because Cobra uses C# as its back-end. While this has some nice advantages, it has the disadvantage of being slow.