Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Scripting with C#/Mono...in C#/Mono  (Read 3911 times)

0 Members and 1 Guest are viewing this topic.

MarekkPie

  • Newbie
  • *
  • Posts: 19
    • View Profile
Scripting with C#/Mono...in C#/Mono
« on: March 01, 2012, 09:48:34 pm »
Maybe I am missing something obvious, but there doesn't seem to be a lot of information about using C#/Mono as a scripting language for projects already written in C#/Mono. There is plenty of information on how to do it in a C++ project, and there are some rare examples of doing it inside C#/Mono, but I have yet to get one of them to build successfully on my machine.

The two options I seem to think are viable are using the Mono.CSharp Evaluator class, or through the dynamic type. However, all the examples using the Evaluator have either failed, or only loaded a single statement at a time, and I am unsure that using the dynamic type would correctly cast a SFML.Vector2 (plus I am unsure if Mono currently supports the dynamic type.)

Even if there aren't any straight up tutorials out there, are they any examples out there of this that I could look through the source code of?

Thanks in advance.

omeg

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • http://omeg.pl/
Scripting with C#/Mono...in C#/Mono
« Reply #1 on: March 01, 2012, 11:04:19 pm »
One way is to use runtime compilation to compile your script into an assembly and then load it.

MarekkPie

  • Newbie
  • *
  • Posts: 19
    • View Profile
Scripting with C#/Mono...in C#/Mono
« Reply #2 on: March 01, 2012, 11:38:57 pm »
Isn't the point of scripting to not need the compilation step? I haven't ever embedded scripts into anything I've done, but I was always under the impression that scripting worked by allowing people fine-tune something without compilation. For example, if I were building the GUI front end of an application, and I wasn't using a graphical editor (like Glade for Mono or Stetic for Monodevelop), then if I were to "script" the visual variables - coordinates, art assets, descriptive text - I could simply reload the file and have that information be updated.

omeg

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • http://omeg.pl/
Scripting with C#/Mono...in C#/Mono
« Reply #3 on: March 02, 2012, 09:50:31 am »
C# isn't interpreted language. You can easily compile code in runtime without any external compilers, just use System.CodeDom.Compiler:
http://msdn.microsoft.com/en-us/library/system.codedom.compiler.aspx
http://stackoverflow.com/questions/826398/is-it-possible-to-dynamically-compile-and-execute-c-sharp-code-fragments

 

anything