🔒 Locked
Using C# as a scripting language
Advertisement
Original Post
I'm using C#, and I'm dynamically compiling C# scripts for my game...
Within my C# scripts I need to call a function. For example:
Game code:
Script code:
Within my C# scripts I need to call a function. For example:
Game code:
public class MyClass{ void MovePlayer(int distance); void Loop() { ExecuteScript("Thisscript.script"); }}Script code:
void Script(){ MyClass.MovePlayer(3);}
You have to pass the assemblies containing the classes to be exported for scripting to the CS compiler. The flag for the MS compiler is: /r:
I'd strongly set against this idea, however. Even with C# there are security implications by doing this. It's possible for someone to write a script for your game that could possibly do things such as completely remove a person's HK_CURRENT_USER key tree in the registry, especially if you aren't careful with your assembly references. I'd go, if I were you, with a more traditional scripting language such as Python or Lua, or even SmallC.
I'd strongly set against this idea, however. Even with C# there are security implications by doing this. It's possible for someone to write a script for your game that could possibly do things such as completely remove a person's HK_CURRENT_USER key tree in the registry, especially if you aren't careful with your assembly references. I'd go, if I were you, with a more traditional scripting language such as Python or Lua, or even SmallC.
I started a thread on .NET scripting. Got some really sweet replies too - might be worth an eyeball.
Well, two things really.
First: You will either need to use Managed C++/COM to expose your game functionality. Or you can use C function wrappers.
Secondly:
I can do ALL of those same things in all 3 of the languages you mentioned. If he's using C# he can setup an AppDomain that allows only certain assemblies to be loaded, along with security settings to disallow access to pretty much anything you don't want exposed. You can't do that in Python, Lua, or SmallC.
First: You will either need to use Managed C++/COM to expose your game functionality. Or you can use C function wrappers.
Secondly:
Quote:
I'd strongly set against this idea, however. Even with C# there are security implications by doing this. It's possible for someone to write a script for your game that could possibly do things such as completely remove a person's HK_CURRENT_USER key tree in the registry, especially if you aren't careful with your assembly references. I'd go, if I were you, with a more traditional scripting language such as Python or Lua, or even SmallC.
I can do ALL of those same things in all 3 of the languages you mentioned. If he's using C# he can setup an AppDomain that allows only certain assemblies to be loaded, along with security settings to disallow access to pretty much anything you don't want exposed. You can't do that in Python, Lua, or SmallC.
When I did it, I added a referenced assembly to the CompilerParameters of the compiler created by the code provider. I eventually abandoned the project because once you have the assembly created, you can't easily get rid of it.
The next thing I'm looking at is VSA (Visual Studio for Applications), basically it seems like an the .NET version of VBA. I've not used it too much at present as I went onto use plugins (because this is a work project). But when I get the time, I'll go back to VSA because it seems to be where it's at, yo.
The next thing I'm looking at is VSA (Visual Studio for Applications), basically it seems like an the .NET version of VBA. I've not used it too much at present as I went onto use plugins (because this is a work project). But when I get the time, I'll go back to VSA because it seems to be where it's at, yo.
I just wanted to point out that .NET 2.0 will allow dynamic generation of methods with something called LCG, and allow you to garbage collect generated methods when you're done with them. That provides a semi-fix for the garbage collection issue with assemblies that was mentioned earlier.
Also, it is supposedly possible to load an assembly in its own AppDomain and then get rid of the custom appdomain to get rid of it when you're done, but I'm not sure how well that would work.
Also, it is supposedly possible to load an assembly in its own AppDomain and then get rid of the custom appdomain to get rid of it when you're done, but I'm not sure how well that would work.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement