Jump to content

  • Log In with Google      Sign In   
  • Create Account

Scripting in C#/XNA


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 RobeeZ   Members   -  Reputation: 206

Like
0Likes
Like

Posted 18 August 2012 - 03:57 PM

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

Sponsor:

#2 ApochPiQ   Moderators   -  Reputation: 15832

Like
1Likes
Like

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.

Edited by ApochPiQ, 18 August 2012 - 04:48 PM.
Addition


#3 RobeeZ   Members   -  Reputation: 206

Like
0Likes
Like

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

Edited by RobeeZ, 19 August 2012 - 03:47 AM.


#4 Mito   Members   -  Reputation: 855

Like
0Likes
Like

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.

#5 6677   Members   -  Reputation: 1058

Like
0Likes
Like

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS