xsharp.eu • X# Scripting question
Page 1 of 2

X# Scripting question

Posted: Wed May 31, 2017 6:28 am
by wriedmann
Hello,

First: let me say that is impressive what the script compiler can do!

I have a few question about the new scripting support in X#:

- can we distribute the script compiler with our applications? Or move it even to other systems? What is the license of the script compiler?
- is it possible to embed the script compiler in our applications? This could be important because then scripts can be executed in the context of our program, using all classes and methods defined there.
- is there any documentation available?

Thank you very much!

Wolfgang

X# Scripting question

Posted: Wed May 31, 2017 10:37 am
by robert
Wolfgang,

Valid questions.

1) Look at the "c:Program Files (x86)XSharpRedistRedist.txt"
It states that you can distribute the files
- Xsi.exe
- XSharp.Scripting.dll
- XSharp.CodeAnalysis.dll

and the support files (which are from Microsoft)

2) You can embed the scripting in your apps. The XIDE folder in the Scripting Examples folder shows many examples on how to do that

3) At this moment the docs are limited. Look at https://www.xsharp.eu/help/x-scripting.html for the text from the slides of the session that Nikos did in Cologne.

You can also look at the C# Roslyn scripting API examples on https://github.com/dotnet/roslyn/wiki/Scripting-API-Samples.
Our scripting is based on the same api. The only difference are the namespaces.
Where the C# examples require

Code: Select all

using Microsoft.CodeAnalysis.CSharp.Scripting
using Microsoft.CodeAnalysis.Scripting
we require

Code: Select all

USING LanguageService.CodeAnalysis.Scripting
USING LanguageService.CodeAnalysis.XSharp.Scripting
Robert

X# Scripting question

Posted: Wed May 31, 2017 11:56 am
by wriedmann
Hi Robert,

thank you for pointing me to the help page - I hadn't searched there.

What you have accomplished with scripting is really great - I see a lot of things I can do with it (I have worked a lot with VOScript in the past).

Wolfgang

X# Scripting question

Posted: Tue Jul 18, 2017 9:36 am
by wriedmann
Hi,

I'm trying to integrate scripting in my program. I need to evaluate simple expressions like

Code: Select all

length * price
but I cannot even evaluate an expression like

Code: Select all

3 + 4
This is my code:

Code: Select all

method Process( cScriptCode as string )	as string
local cReturn as string
local oReturn as object
	
cReturn	:= "" 
oReturn := XSharpScript.EvaluateAsync( cScriptCode, ScriptOptions.Default, _oParameters ) 
cReturn	:= oReturn:ToString()
	
return cReturn
(of course in a try/catch block!)
But it gives me an exception
ScriptException.png
ScriptException.png (4.62 KiB) Viewed 377 times
Can you give me an hint, please?

You can also find a viaef file of the application attached to this message.

Thank you very much!

Wolfgang
P.S. I need this in my Door Configurator and I would not add any dependency on Vulcan on this Core application

X# Scripting question

Posted: Tue Jul 18, 2017 12:51 pm
by FFF
Sorry, no hint, but a confirmation ;)

Karl

X# Scripting question

Posted: Tue Jul 18, 2017 12:59 pm
by wriedmann
Hi Karl,

do you have played with this or only used my code?

I have now found an alternative tool:

https://ncalc.codeplex.com/releases/view/73656

And it seems to do what I need, had only to rebuild it for .NET 4.
ncalc_sample.png
ncalc_sample.png (3.2 KiB) Viewed 378 times
Took me about 5 minutes to make it work.

Wolfgang

X# Scripting question

Posted: Tue Jul 18, 2017 1:02 pm
by wriedmann
Hi Karl,

if you like playing with it a bit: please find attached a working sample.

Wolfgang

X# Scripting question

Posted: Tue Jul 18, 2017 1:33 pm
by FFF
Played with your code, pure curiosity ;)
Confirm, that the ncalc tool works. But would like to see, where the error in your first version comes from...

K.

X# Scripting question

Posted: Tue Jul 18, 2017 1:39 pm
by wriedmann
Hi Karl,

since I need a solution today, I'll go the NCalc route. But of course I would prefer the X# scripting engine...

Maybe I can replace NCalc later. It is interesting to see that it uses Antlr like the X# compiler and the Vulcan compiler.

Wolfgang

X# Scripting question

Posted: Tue Jul 18, 2017 1:53 pm
by Chris
Hi Wolfgang,

I saw the same problem with your app, checked what's different with the samples I have from Nikos' session in Cologne and found out that you need to include a .exe.config file like the attached one.

This will take care of the problem loading the .dll, but now I see some other runtime issues with the newest x# dlls, while it worked ok with a previous version. We'll look into this ASAP.

Chris