fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: X# Scripting question

X# Scripting question 1 year 9 months ago #1

  • wriedmann
  • wriedmann's Avatar Topic Author
  • Online
  • Posts: 1404
  • Karma: 6
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
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

X# Scripting question 1 year 9 months ago #2

Wolfgang,

Valid questions.

1) Look at the "c:\Program Files (x86)\XSharp\Redist\Redist.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.info/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
using Microsoft.CodeAnalysis.CSharp.Scripting
using Microsoft.CodeAnalysis.Scripting
we require
USING LanguageService.CodeAnalysis.Scripting
USING LanguageService.CodeAnalysis.XSharp.Scripting

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

X# Scripting question 1 year 9 months ago #3

  • wriedmann
  • wriedmann's Avatar Topic Author
  • Online
  • Posts: 1404
  • Karma: 6
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
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

X# Scripting question 1 year 8 months ago #4

  • wriedmann
  • wriedmann's Avatar Topic Author
  • Online
  • Posts: 1404
  • Karma: 6
Hi,

I'm trying to integrate scripting in my program. I need to evaluate simple expressions like
length * price
but I cannot even evaluate an expression like
3 + 4
This is my code:
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


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
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it
Attachments:

Please Log in or Create an account to join the conversation.

X# Scripting question 1 year 8 months ago #5

Sorry, no hint, but a confirmation ;)

Karl

Please Log in or Create an account to join the conversation.

X# Scripting question 1 year 8 months ago #6

  • wriedmann
  • wriedmann's Avatar Topic Author
  • Online
  • Posts: 1404
  • Karma: 6
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.



Took me about 5 minutes to make it work.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it
Attachments:

Please Log in or Create an account to join the conversation.

X# Scripting question 1 year 8 months ago #7

  • wriedmann
  • wriedmann's Avatar Topic Author
  • Online
  • Posts: 1404
  • Karma: 6
Hi Karl,

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

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it
Attachments:

Please Log in or Create an account to join the conversation.

X# Scripting question 1 year 8 months ago #8

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.

Please Log in or Create an account to join the conversation.

X# Scripting question 1 year 8 months ago #9

  • wriedmann
  • wriedmann's Avatar Topic Author
  • Online
  • Posts: 1404
  • Karma: 6
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
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

X# Scripting question 1 year 8 months ago #10

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
XSharp Development Team
chris(at)xsharp.eu
Attachments:

Please Log in or Create an account to join the conversation.

X# Scripting question 1 year 8 months ago #11

  • wriedmann
  • wriedmann's Avatar Topic Author
  • Online
  • Posts: 1404
  • Karma: 6
Hi Chris,

thank you very much!

When you are ready, I'll need to find an alternative way to the .config file as I have to implement this functionality in a DLL library (that is loaded dynamically at runtime).

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

X# Scripting question 1 year 8 months ago #12

  • wriedmann
  • wriedmann's Avatar Topic Author
  • Online
  • Posts: 1404
  • Karma: 6
Hi,

if someone is interested: Chris has sent me yesterday an old version of the scripting DLLs, and they work now.

This is the code:
method Process( cScriptCode as string ) as string 
local cReturn as string
local oReturn as object
	
cReturn := "" 
try                   
		
oReturn := XSharpScript.EvaluateAsync( ;
    cScriptCode, ScriptOptions.Default, _oParameters ):Result
cReturn	:= oReturn:ToString()
		
catch oEx as Exception
		
MessageBox.Show( _oOwner, oEx:Message, "Script error" )
		
end try
	
return cReturn

and I had to add a .config file with the following content:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
    </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
      </dependentAssembly>
    </assemblyBinding>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.2.1.0" newVersion="1.2.1.0" />
      </dependentAssembly>
    </assemblyBinding>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

and a few DLLs more:

System.Collections.Immutable.dll
System.IO.FileSystem.dll
System.Reflection.Metadata.dll
System.Security.Cryptography.Algorithms.dll
System.Security.Cryptography.Primitives.dll
System.Text.Encoding.CodePages.dll
System.ValueTuple.dll
System.Xml.ReaderWriter.dll
XSharp.CodeAnalysis.dll
XSharp.CodeAnalysis.dll.config
XSharp.Scripting.dll

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

X# Scripting question 1 year 8 months ago #13

  • wriedmann
  • wriedmann's Avatar Topic Author
  • Online
  • Posts: 1404
  • Karma: 6
To complete my message: attached to this message you will find a zip archive with the application source as XIDE export file and the needed DLLs.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it
Attachments:

Please Log in or Create an account to join the conversation.

X# Scripting question 1 year 7 months ago #14

Wolfgang,

Would it help if we build the scripting DLL against the .Net Framework in stead of .Net Standard, so you it depends on less assemblies?

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

X# Scripting question 1 year 7 months ago #15

  • wriedmann
  • wriedmann's Avatar Topic Author
  • Online
  • Posts: 1404
  • Karma: 6
Hi Robert,

yes, that would definitely help. Since .NET Standard has no GUI, there is no possibility to build GUI applications against .NET Standard.

For web server applications it would be better to have .NET Standard. Maybe you could deliver both versions?

Thank you for asking!

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

  • Page:
  • 1