X# Scripting question

This forum is meant for questions and discussions about the X# language and tools
User avatar
wriedmann
Posts: 3765
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

X# Scripting question

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4540
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

X# Scripting question

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
wriedmann
Posts: 3765
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

X# Scripting question

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3765
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

X# Scripting question

Post 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 724 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
Attachments
ScriptTest.zip
(3.24 KiB) Downloaded 68 times
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1584
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

X# Scripting question

Post by FFF »

Sorry, no hint, but a confirmation ;)

Karl
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
wriedmann
Posts: 3765
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

X# Scripting question

Post 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 725 times
Took me about 5 minutes to make it work.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3765
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

X# Scripting question

Post by wriedmann »

Hi Karl,

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

Wolfgang
Attachments
ScriptTest_ncalc.zip
(109.99 KiB) Downloaded 64 times
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1584
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

X# Scripting question

Post 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.
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
wriedmann
Posts: 3765
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

X# Scripting question

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Chris
Posts: 4936
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

X# Scripting question

Post 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
Attachments
execonfig.zip
(504 Bytes) Downloaded 65 times
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply