向.NET应用程序添加脚本功能 [英] Adding scripting functionality to .NET applications

查看:111
本文介绍了向.NET应用程序添加脚本功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#写的游戏。它使用数据库作为后端。这是
a 交易卡游戏,我想实现卡的功能一个脚本。

I have a little game written in C#. It uses a database as back-end. It's a trading card game, and I wanted to implement the function of the cards as a script.

我的意思是,我本质上有一个接口, ICard public class Card056:ICard ),其中包含游戏调用的函数。

What I mean is that I essentially have an interface, ICard, which a card class implements (public class Card056 : ICard) and which contains function that are called by the game.

现在,事情可维护/可修改,我想让每个卡的类作为数据库中的源代码,并且基本上在首次使用时编译它。因此,当我需要添加/更换卡时,我只需将其添加到数据库中,并告诉我的应用程序刷新,而不需要任何组件部署(特别是因为我们将讨论每个卡一个程序集,这意味着几百个程序集) 。

Now, to make the thing maintainable/moddable, I would like to have the class for each card as source code in the database and essentially compile it on first use. So when I have to add/change a card, I'll just add it to the database and tell my application to refresh, without needing any assembly deployment (especially since we would be talking about 1 assembly per card which means hundreds of assemblies).

这是可能吗?从源文件注册一个类,然后实例化它等。

Is that possible? Register a class from a source file and then instantiate it, etc.

ICard Cards[current] = new MyGame.CardLibrary.Card056();
Cards[current].OnEnterPlay(ref currentGameState);

语言是C#,但如果可以用任何.NET语言编写脚本,

The language is C#, but extra bonus if it's possible to write the script in any .NET language.

推荐答案

Oleg Shilo的C#脚本解决方案(在代码项目)真的是一个伟大的介绍,在您的应用程序提供脚本能力。

Oleg Shilo's C# Script solution (at The Code Project) really is a great introduction to providing script abilities in your application.

一种不同的方法是考虑专门为脚本编写的语言,例如 IronRuby IronPython Lua

A different approach would be to consider a language that is specifically built for scripting, such as IronRuby, IronPython, or Lua.

IronPython和IronRuby今天都可以使用。

IronPython and IronRuby are both available today.

有关嵌入IronPython的指南,请参阅
如何在10个简单步骤中将IronPython脚本支持嵌入现有应用程序< a>。

For a guide to embedding IronPython read How to embed IronPython script support in your existing app in 10 easy steps.

Lua是游戏中常用的脚本语言。有一个用于.NET的Lua编译器,可从CodePlex获取 - http: //www.codeplex.com/Nua

Lua is a scripting language commonly used in games. There is a Lua compiler for .NET, available from CodePlex -- http://www.codeplex.com/Nua

如果您想了解如何在.NET中构建编译器,那么该代码库是一个伟大的阅读。

That codebase is a great read if you want to learn about building a compiler in .NET.

另一个不同的角度是尝试 PowerShell 。有很多将PowerShell嵌入应用程序的例子 - 这是一个关于这个主题的彻底的项目:
Powershell Tunnel

A different angle altogether is to try PowerShell. There are numerous examples of embedding PowerShell into an application -- here's a thorough project on the topic: Powershell Tunnel

这篇关于向.NET应用程序添加脚本功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆