Hi!
I want my engine to use scripts, and I have a List<Script>. Each Script object holds information about a script: name, source code, etc. If I use CodeDomCompiler it will create a DLL. It's not bad as long as I don't want to recompile the script, but I want to edit those sources runtime, and then I cant recompile, because it cant overwrite the DLL. I thought about Lua and Python, but why use those, when I have C# here? Or can't I just compile them into the memory without creating any assembly? Or is there any way interpreting the scripts? (Searching on google gave no results for me)
Thanks in advance
Scripting in C#/XNA
Started by RobeeZ, Aug 18 2012 03:57 PM
4 replies to this topic
Sponsor:
#2 Moderators - Reputation: 7561
Posted 18 August 2012 - 04:46 PM
When you invoke the compiler, you can pass it a series of options. See the list here. There are options for setting the output file name as well as generating an in-memory buffer of code.
[edit] When generating an assembly in-memory you can use the CompilerResults object to get a reference to the Assembly object that corresponds to your built code. Accessing that property should automatically load the compiled assembly into your program.
[edit] When generating an assembly in-memory you can use the CompilerResults object to get a reference to the Assembly object that corresponds to your built code. Accessing that property should automatically load the compiled assembly into your program.
Edited by ApochPiQ, 18 August 2012 - 04:48 PM.
Addition
#3 Members - Reputation: 158
Posted 19 August 2012 - 03:28 AM
That's ok, I tried them, using GenerateInMemory = true, but when I use the result (Assemby a = result.CompiledAssembly), then it throws an exception that it couldnt load the xxxxxx.dll.
Edit: I don't know what I did, but now working. Interesting
Edit: I don't know what I did, but now working. Interesting
Edited by RobeeZ, 19 August 2012 - 03:47 AM.
#4 Members - Reputation: 617
Posted 21 August 2012 - 12:53 PM
Code project to the rescue: http://www.codeproject.com/Articles/113169/C-As-A-Scripting-Language-In-Your-NET-Applications
also, you SHOULD be able to rewrite the DLL if you don't have a static reference to it. but you will need to clear the assembly from the AppDomain before replacing the file...
better just compile on the fly or use the scripting engine.
also, you SHOULD be able to rewrite the DLL if you don't have a static reference to it. but you will need to clear the assembly from the AppDomain before replacing the file...
better just compile on the fly or use the scripting engine.
#5 Members - Reputation: 1050
Posted 23 August 2012 - 07:26 AM
IronPython can actually be used as a python interpreter embedded into .net applications. Theres a few lua interpreters. I've also seen a few demonstrations of using C# as a scripting language but I assume the above links are something todo with that.






