简体   繁体   中英

Implementing a scripting language in C#

We got a project where we're supposed to let 3rd party developers create their own GUI / CodeBehind drivers. Our GUI is running on WPF.

Now, we got a number of possibilities for doing so, but one of the things we're considering is to create some sort of sub-Xaml XSD to let the create their GUI using markup (dunno if it'll be XAML or our own XML-"language", and then let them do their code-behind through a scripting language.

I thought about it, and this model seems to have many similarities to the way World of Warcraft let's people create their own GUI. The way WoW does it, is by implementing the LUA scripting language and then expose some of their own API calls. We want similar behaviour.

However, we're on a sort-of strict deadline, and this implementation ain't the highest of our priorities. Therefore I'm looking for a .Net compliant script parser / "compiler", to use in our project. Which scripting language we're using is not a major concern, we just want to be able to implement it rather fast, without too much fuzz.

Does anyone know of this sort of library? Or do you guys have a smarter solution for these requirements?

Obviously, we're dreaming of creating our own WYSIWYG editor and our own domain specific language, but this seems like overkill for us. We just want a scripting language which can do nothing but to do calls though our API while letting the 3rd party developer use conditionals, loops, maybe OO, etc..

Thanks in advance :)

You can use IronPython as your scripting language. Here's an article that gives a basic idea how you can do it.

你看过CSScript了吗?

Lua plus LuaInterface is the choice for our current project - just register methods from your API with LuaInterfcae and they can be called from script code. Our user interface uses Scintilla and ScintillaNET for script editors.

This is probably not the best solution for building complex user interfaces, but it is possible.

I strongly agree. Inventing new general-purpose "script a bunch of control flow and object model invocations" language is "minus one thousand points" on my team; that is, the cost of doing so is so high, and the cost to our customers of having to learn a new language is so high, that the benefit has to be at least "a thousand points" just to get out of negative territory. There are plenty of scripty languages that you don't have to design, specify, develop, test, debug, document, ship, maintain and teach your customers how to use; you can avoid all those costs.

If I were in your shoes I would only be developing a new language if its value was that it was very different from every other language out there, due to its special-purpose applicability to a specific domain. It sounds like you are well on your way to developing a static markup DSL, which is a great idea. By making it a subset of an existing tag-structured language you don't have to take on the burdens of building parsers and lexical verifiers and whatnot.

Have you considered creating a DSL in Boo ?.

It doesn't have to be very hard and complex to get started, but you get excellent options for expanding the DSL if you get more time on your hands later on.

Antlr is a lexer/parser generator. It is a little more involved than just using Iron Python, however, you are able to create your own DSL fairly easily, allowing only the types of operations you want.

With the generated parser/lexer you can use it as a real time interpreted language, or a traditional statically compiled, or use it to generate C# code, which then gets compiled.

The options are quite endless.

也许你兴趣重新发明轮子,或者想要更好地理解如何用C#编写自己的编程语言工具,请参阅CodeProject.com上使用C#实现编程语言

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM