Welcome, Guest
Username: Password: Remember me
Please use this forum for suggestions to the XSharp Development Team
  • Page:
  • 1


An advice. 22 Feb 2023 11:52 #25346

  • softdevo@tiscali.it's Avatar
  • Topic Author

  • Posts: 177
  • Hi to all,
    In my web application I have a page that is built dynamically with the instructions contained in a table.
    In the page I can insert Label, TextBox, Dropdownlist, Button and more.
    For the Button I currently indicate in the table the name of the method to be called when the Button is pressed. The method is now in a DLL.
    I wonder: do you think I could put the method and its code in a column of the same table and execute this code using X# scripts? Are the scripts reliable? Is it possible to write everything or are there limits? do you have any example? thanks and sorry again.
    Thank's to all

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

    An advice. 22 Feb 2023 12:11 #25347

    • SHirsch
    • SHirsch's Avatar

  • Posts: 279
  • Hello Danilo,

    scripting is very powerful and reliable. It's compiled as an in-memory dll.
    If you have many script functions memory consumption increase rapidly, because every compile need its memory. I had the same issue. So if your scripts won't change at runtime you could collect all your scripts merge them into one big script. This is a bit tricky because you have the merge USINGs and create LOCAL FUNCTIONS or CLASSes. Than compile this big script and than you can call your functions from this big script.
    Attached a small sample. The xs files are the single scripts. The merged.xsx is the merged script. To give you an idea how this could look like. Instead of compiling and calling the single script the merged script is compiled an then a function from is called. As you see the function name is name of the (I have all scripts as files).


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

    An advice. 22 Feb 2023 17:59 #25355

    • softdevo@tiscali.it's Avatar
    • Topic Author

  • Posts: 177
  • Thanks, but do you know where I can find some example of code reading and subsequent execution? some small application that at runtime reads and executes scripts?


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

    An advice. 24 Feb 2023 13:10 #25395

    • robert
    • robert's Avatar

  • Posts: 3599
  • Danilo,
    For scripting there are 2 possibilities:
    1) use the "old" scripting that is based on the Roslyn Scripting. This is very powerful and allows you to even declare classes and methods in the script. These scripts are compiled into in memory assemblies and cannot be unloaded. So if you have a component that keeps running, this may cause memory problems after a while.
    You will find some examples in the c:\Users\Public\Documents\XSharp\Scripting\XIDE folder on your machine. this is based on a session that Nikos did a few years ago on a conference
    2) use the new "ExecScript()" function in the runtime. This allows you to execute a list of statements stored inside a string. You could see this list of statements as a method without header. You can receive parameters inside the script with the LPARAMETERS statement (this declares locals) or with the PARAMETERS statement (this declares privates).
    The macro compiler will compile this into dynamic methods, that will be unloaded automatically when no longer in uses. So this uses less memory. I showed some examples of this in my online session about scripting.
    You can declare locals with a type and also use VAR to derive the type at runtime. variables declared with LPARAMETERS are untyped, but you can assign these to typed locals if you want for better performance

    Unfortunately there is not much to "read" about this. Maybe there is a volunteer that wants to write something ?

    I think the example from STEFAN was based on the "old" scripting engine, since his merged file contains FUNCTION declarations.

    XSharp Development Team
    The Netherlands

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

    • Page:
    • 1