- Home /
Interpreted Scripting
I am currently working on a project and for the moment it is just being made for the sake of it. However I want to know of my options if I ever planned to port it over to a mobile device.
I need to get some kind of interpreted scripting into my project and I figure I have 3 options. Do any of these work for unity and specifically for the iPhone/Android mobile platforms:
- c#'s code compile classes
- Javascript's eval function
- Something like Lua or Python
Any advice appreciated, I really don't want to have to write some simple scripting classes myself.
Answer by Peter G · Feb 21, 2011 at 06:44 PM
Interesting question. As long as you are making your stand alone in Unity, it will port your code for you. So you don't need to worry or make use of any interpreter. If that is not the case, then I suggest you read on.
If you need to use these dynamic features for a gameplay element, then I would use Reflection. Almost all the classes for reading and writing files are included in your build, but I don't know if self-generating code classes are such as System.CodeDOM
. I know that it is included in the editor, but it is used in mostly special circumstances in game so for most people it would just increase build size.
If you want to see what is included, open MonoDevelop/VisualStudio and examine the references. Look through the System Namespace and see what files are included. Note: it will not include every namespace listed on the .Net online reference. Unity leaves out some such as System.Windows
for memory's sake.
Writing your own interpreter is risky. Technically Unity gives you the resources that you could do it. Apple is finicky about what they will allow hence Unity is JIT compiled on desktop and AOT compiled on iPhone.
Android is already interpreted. Unity uses the Dalvik Virtual Machine to access native C++ code so on Android, you could probably use your own interpreter, but I'm not an Android dev so I can't tell you for sure.