0

I am searching for a Script-Language for my product, which will allow easy customisation.

I have built my own small XML-Based language, but i'm not really happy with this solution:

<ScrArp>
    <StaticClass Name="Root">
        <Method Return="Void" Name="Main">
            <Call Method="Print" Text="Hello World" />

            <Declare Type="SampleClass" Name="myInstance">
                <Set>
                    <NewInstance Type="SimpleClass" />
                </Set>
            </Declare>

            <Call Text="Hello 123">
                <Instance Name="myInstance">
                    <!-- <Instance Name="mySample2..."> -->
                    <Method Name="TestMethod" />
                    <!-- </Instance> -->
                </Instance>
            </Call>
        </Method>
    </StaticClass>

    <Class Name="SampleClass">
        <Method Return="Void" Name="TestMethod">
            <Parameter>
                <Declare Type="String" Name="Text" />
            <Parameter>
            <Call Method="Print">
                <Text>
                    <Get Name="Text" />
                </Text>
            </Call>
        </Method>

        <Method Return="String" Name="Method2">
            <Declare Type="String" Name="cReturnValue" />

            <Set>
                <Instance Name="cReturnValue" />
                <Value>
                    <Call>
                        <Instance Name="cReturnValue" />
                    </Call>
                <Value>
            </Set>

            <Return>
                <Instance Name="cReturnValue" />
            <Return>
        </Method>
    </Class>
</ScrArp>

I have used Lua and IronPython before, but i don't like Lua that much and as far as i know IronPython is only community supported.

Now my Question. Which is the best solution for scripting in C#? - IronPython - Lua - My Own Small Language?

Thank's!

1

3 Answers 3

6

If you want to go the hard way, I would recommend spending the next 6 months or so trying to write your own "compiler". If you want an easier way, I would recommend you offer scripting in actual C# language and use CodeDOM to compile and execute.

In order to properly use the generated/compiled assemblies I recommend you force the usage of interfaces by the end users and use Dependency Injection in your application.

EDIT :

Following your edit on the question. To be honest I have no clue about neither Lua or IronPython, but something I know for sure: you should NEVER EVER try reinventing the wheel. DON'T try writing your own language. I do remember spending 3 months trying to write my own small ORM (SQL Generator for Dapper) to end up by suddenly discovering ServiceStack ORMLite which was waaaaay more better and offered higher performance than my code.

As I previously explained I would really recommend using C# (since you are also using it in your application).

Sign up to request clarification or add additional context in comments.

6 Comments

I also thought about the CodeDOM solution. But than i had to restart my application, if i want to change some thing in my script.
No you don't. If you are using dependency injection the generated assemblies will not be part of your application (not hard coded dependencies exist), therefore you can regenerate them and simply reuse them as long as them still implement the interface you are using (like you have a new assembly)
"DON'T try writing your own language". If everyone listened to that advice, where would we be?
@MarkWalsh The calendar says 2013 not 1960s. What about not reinventing the wheel?
@MarkWalsh: The question is not looking for a way to achieve something not existent yet or so. This is looking for which solution is the best to implement within a specific application. Again, reinventing the wheel will still lead you to a wheel. We are not discussing the Mars expedition vehicle.
|
1

You could use C# for adding functionality to your application while compiling the code or evaluating expressions from within your application. This can be accomplished using the .NET framework, without relying on community-supported components, but there are community-supported libraries that you can learn from if you choose to write your own code.

Here's an article on how to compile from your application: http://www.codeproject.com/Articles/9019/Compiling-and-Executing-Code-at-Runtime

There's the C# Eval library available for evaluating expressions at runtime as well: http://csharp-eval.com/HowTo.php

Comments

1

You can use PascalScript and maXbox4 #maxbox4 Studio to build your own types and syntax. maXbox is a script tool engine, compiler and source lib all in one exe to design and code your scripts in a shellbook! Pure Code for Object Scripting. Principle is simplicity and reduce to the max. The App is “out of the box” (self containment) and needs no installation nor registration.

Pascal Script is a scripting language based on the programming language Delphi/Pascal that facilitates automated runtime control over scriptable applications and server software. It is implemented by a free scripting engine that includes a compiler and an interpreter for byte code.

1 Comment

now in a 64bit beta release: Release Notes maXbox 5.0.2.40 Dec. 2023 mX502 beta64-bit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.