Login | Register  
Latest 20 PostsMinimize
28 Aug 2010 08:51 PM
RE: MONO - Fastalanasa
28 Aug 2010 01:51 AM
RE: MONO - Taliesen
28 Aug 2010 01:31 AM
RE: MONO - Fastalanasa
27 Aug 2010 04:10 PM
RE: MONO - Taliesen
27 Aug 2010 03:16 PM
RE: MONO - Fastalanasa
27 Aug 2010 09:26 AM
RE: MONO - Karak
27 Aug 2010 05:04 AM
RE: MONO - Taliesen
25 Aug 2010 04:00 PM
RE: MONO - Fastalanasa
25 Aug 2010 04:49 AM
RE: MONO - Taliesen
23 Aug 2010 04:19 AM
RE: MONO - Fastalanasa
23 Aug 2010 02:57 AM
23 Aug 2010 02:54 AM
RE: MONO - Taliesen
23 Aug 2010 02:52 AM
RE: MONO - Fastalanasa
23 Aug 2010 02:36 AM
RE: MONO - Fastalanasa
23 Aug 2010 02:13 AM
RE: Stat System - Fastalanasa
23 Aug 2010 01:57 AM
23 Aug 2010 01:34 AM
23 Aug 2010 01:32 AM
23 Aug 2010 01:30 AM
23 Aug 2010 01:07 AM
ForumsMinimize
CS-Script engine
Last Post 27 Apr 2010 05:53 AM byfeverdream. 3 Replies.
Printer Friendly
Sort:
NextNext
You are not authorized to post a reply.
AuthorMessages
SaquivorUser is Offline
the SharpElf
New Member
New Member
Send Private Message
Posts:12

--
16 Jun 2009 09:02 AM  

I came accross A C# scripting engine a while ago, but my account was not active at time so never got round to posting the information.

The features of the engine are listed here.  There is also source code available etc.

It maybe not relevant, but let me know what you think.


Saq

KarakUser is Offline
Locutus of WheelMUD
Advanced Member
Advanced Member
Send Private Message
Posts:501
Avatar

--
16 Jun 2009 09:22 AM  

Check out the _references folder you already have - it's already been on our radar.

Personally I am against the idea of supporting self-editing scripting for a number of reasons.  I ranted pretty heavily on that already.

FastalanasaUser is Offline
Grumpy Half-Elf
Advanced Member
Advanced Member
Send Private Message
Posts:705
Avatar

--
16 Jun 2009 09:33 PM  
I'm already using CSScript for loading custom XML parsers for rulesets. The parsers are just C# classes that CSScript runs every time the MUD starts.
FeverdreamUser is Offline
Basic Member
Basic Member
Send Private Message
Posts:177
Avatar

--
27 Apr 2010 05:53 AM  
Yeah the nice thing about Reflection is that its really easy to run C# code from a string in memory. Its literally only a few lines of code:
using System;
using System.CodeDom.Compiler;
using System.Reflection;
using Microsoft.CSharp;
public static bool Eval_CS_Code(string code, out object retVal)
{
retVal = null;
if (String.IsNullOrEmpty(code))
{
return false;
}
// Our C# compiler.
CodeDomProvider compiler = CodeDomProvider.CreateProvider("CSharp");
// Our C# compiler parameters
CompilerParameters compiler_parameters = new CompilerParameters();
// Set our compiler to work in memory.
compiler_parameters.GenerateInMemory = true;
// Reference some common DLL's..
foreach (string dll in new string[] {
"System.dll",
"System.Data.dll",
"System.Xml.dll",
"System.Windows.Forms.dll"
}// End array
)// End start of foreach
{
compiler_parameters.ReferencedAssemblies.Add(dll);
}// End foreach
// Shove code to run inside of a temp class/method
string[] tmpApp = new string[]
{
"using System;",
"public class Program {",
"public static void Main() {",
code,
"}",
"}",
""
};
// Set new statement now that.
code = String.Join(Environment.NewLine, tmpApp);
// Compile source..
CompilerResults results = compiler.CompileAssemblyFromSource(compiler_parameters, code);
// Did our compile go fubar?
if (results == null)
{
Console.WriteLine("Compiler results are null.");
return false;
}
if (results.Errors.Count > 0)
{
Console.WriteLine("Compile had errors:");
int i = 0;
while (i < results.Errors.Count)
{
Console.WriteLine("Error {0}: {1} on line {2}.",
results.Errors<i>.ErrorNumber,
results.Errors<i>.ErrorText,
results.Errors<i>.Line - 3 // Change index since we edit the code they use.
);
i++;
}
return false;
}
Assembly assembly = results.CompiledAssembly;
Type et = assembly.GetType("Program", false, true);
if (et == null)
{
Console.WriteLine("GetType failed.  User should never see this.");
return false;
}
// C# does not support the style of binding we would love to have..
object evalObj = Activator.CreateInstance(et);
// Not an error that should happen.
if (evalObj == null)
{
Console.WriteLine("Could not activate object from source.");
return false;
}
// Invoke our created function using the entry point we set above.
retVal = et.InvokeMember(
"Main",
BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static,
null,
evalObj,
new object[] { }
);
/* Fix the bug here.*/
return true;
}
.. There you go, everything you need to run C# scripts.. Oh and for the people blindly copy-and-pasting (it looks like this thread gets a lot of hits) keep in mind that yes, my code above does have a hidden bug in it just for you... and learning about it will be half the fun of using that code *grin* I was not going to say anything, but I realized not saying anything may have been cruel..
You are not authorized to post a reply.

Active Forums 4.2
Copyright 2007-2010 by WheelMUD  | Terms Of Use | Privacy Statement
Google Analytics Alternative