Skip to main content
gamedev.net
🔒 Locked

[.net] C#/Net Script language?

Started by ScopeDynamo Oct 18, 2005 at 1:48 PM 6 replies 750+ views
Original Post
ScopeDynamo
ScopeDynamo
Are there any scripts language I can use?(I use VC2005 C# Beta 2, net framework2.0) I heard that it's possible to use C# code directly as scripts? Is this a reference I can use that'll let me do that? Is it possible to expose functions from within my C# program to these C# scripts if so? Any AngelCode wrappers?
Rob Loach
Rob Loach
Me again [wink].

You can use .NET's CodeDom namespace to compile .NET languages like C# and VB.NET. I made a wrapper for the methodology named GakScript. It consists of a wrapper class where you pretty much set the language (C#, JScript, Visual Basic, etc), add the references, add some code in and then compile it. From there you can call methods and execute the script. There are also helper functions like DoCodeFromFile that reads in the code, compiles and executes it for it.

I'm using this for a project I'm currently working on. All tile maps are read in from script files containing the actual code to generate the Map object. GakScript comes with a few example programs that you can play with. Enjoy!
Rob Loach [Website] [Projects] [
Washu
Washu
You could also look at the D3DSDK samples, they have one that shows embedding C# scripts with security.
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
mutex
mutex
There are a variety of scripting languages out there. An interesting one is boo.

As for scripting with C#, all the methods I've seen essentially involve compiling C# to a temporary assembly (DLL) and loading it. The problem is that you can't unload assemblies directly; you have to put them in an AppDomain and unload an entire AppDomain to unload them. Morever, there are subtle issues involved with taking the AppDomain route. Of course, this isn't a problem if you don't need to unload scripts.

Here's a C# dynamic compiling article.

ScopeDynamo
ScopeDynamo
Rob, I saw another script engine similar to yours but I'm just wondering if they can be used like actual scripts. I.e can I pass data to and from the scripts without saving it to disk? I guess I can do a using type thing to get identical strucutres if I use C#, but is there anything like,

Script MyScript = ScriptEngine.Load("MyScript.cs")
MyScript.RegisterMethod( MyMethodDelegate)

or similar? with a means to extract and send back return data? Like Lua really.

Thanks for the other suggestions too, i'll check 'em out.
Rob Loach
Rob Loach
Quote:
Original post by ScopeDynamo
Rob, I saw another script engine similar to yours but I'm just wondering if they can be used like actual scripts. I.e can I pass data to and from the scripts without saving it to disk? I guess I can do a using type thing to get identical strucutres if I use C#, but is there anything like,

Script MyScript = ScriptEngine.Load("MyScript.cs")
MyScript.RegisterMethod( MyMethodDelegate)

or similar? with a means to extract and send back return data? Like Lua really.

Thanks for the other suggestions too, i'll check 'em out.
You can add any compiled assembly to the references of the script file. This means you'd go:

GakScripter script = new GakScripter();script.AddReference("MyScriptFunctions.dll");

This allows the script access to all functionality within the compiled MyScriptFunctions.dll. You could make instances of classes in its namespace, call static methods, etc. I'd like to add a AddSelfReference method or something. The register method idea you brought up is a good one though and I've added it to the Todo list.
Rob Loach [Website] [Projects] [
iwandi
iwandi
LUA .net Warper

http://www.codeproject.com/managedcpp/luanetwrapper.asp

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.