In previous journals we’ve discussed the intention to create a modding layer that would use Python as its scripting language. Python is slower than Lua in terms of interpreted languages but there’s nothing stopping us from having C++ source that people could use to in addition or instead of a scripting language for performance sensitive elements of a game.
With that said, let’s hear from those familiar with both on what they think of either one and why.
I haven't used Lua, and only met Python in passing. C++ on the other hand, I know. Not a guru, but proficient. So what does that mean? I wouldn't be afraid of C++, and certainly feel I could learn Python or Lua. I would lean towards the more 'C-like' choice for obvious biased reasons. From arguments given above I'd choose Python.
Lua and C++
(I think I will stop talking about Python and Lua now and focus on what I consider better options)
Since it was brought up, AngelScript's support for multi-threading is left to the application making use of it. You can have one instance per thread as in Lua. You can have one real thread manage multipe 'script threads' with custom cooperative or pre-emptive multithreading (an add-on is provided with the VM source code to help with thist). Finally, you can have one real thread per 'script thread'.
In terms of memory management, AngelScript is kind of like Python though from what I recall of the API for including Python scripts it gave the application less control. AngelScript allows the host application to tell it what functions to call to allocate and free memory (it defaults to the C Library's malloc and free). Objects are ref counted and it has garbage collection for detecting and dealing with circular references (which is very important, as you would otherwise have memory leaks; and the reason for using a scripting langauge is to avoid that). The collection process and be done incrementally (doing all a bit at a time), destroying all know circular referenced objects, and full cycle (for idle time only as it takes awhile). This allows the application stay reponsive and only stop to collect garbage when the time is right.
As I understand it, the garbage collecting is not thread safe even when AngelScript was configured at compile time to deal with multi-threading. That is why mentioning the threading stuff was important. With one script engine instance per thread, it is not a problem as GC is done on a per engine basis. With the other threading models you control threading and GC therefore you can decide how to deal with this.
AngelScript is made to be embedded in an application and interfaces well with C/C++ modules. All the work is done on the application / native module side, which is more likely to be done by people with better programming skills. This is mainly registering functions, objects, and classes with some work being needed for calling scripts (scripts call native functions the same way you would another function in the script). The types used are the same the application/module uses so there is no conversion needed.
Calling scripts requires more work for native code, but that is generally the case when passing arbitrary data to a function wherever it comes from. As far as I can tell, the application can call the functions registered with the script engine the same way it could functions from scripts [Edit: You can call functions registered with AngelScript the same way as you do the scripts]. This would save the trouble of devising a way to pass arbitrary data to the functions (which is a must when what data is being passed is decided at run-time).
You can see a list of features at: http://www.angelcode.com/angelscript/features.asp
I haven't used Lua but I have used Python quite a bit.
One feature I know that Python has is its modularity. If used with Elemental, it would be extremely easy to integrate multiple mods together. I am not sure how this works with Lua, but this should be an important consideration.
I personally think that Python is very read/write... thats why I like it so much.
I am a C++ gamedev so obviously no problems with C++ option.
The system I would most like to see is the inclusion of two asian computer science majors for every registered serial number pre-FE. That way, I won't have to learn (yet) another coding language.
Or AngelScript which is C++ adapted to be a scripting langauage. It lacks pointers (to ease memory management) and some of the advanced features (templates). And the classes have some Java influence (has interfaces and only single inheritance). But mostly the same.
Sample AngelScript class (pulled from the script reference and slightly modified to show more about it):
I have coded in C++, Lua and Python.
First of all, while being able to code a little in C++ would be useful in the long course, when very complicated mod will happens, it should never be the main way to do so, as it is much harder to learn than the alternatives.
I would tend toward Lua over Python, even though the class syntax is not very pretty, I believe that most mods will mostly rely on functional programming than object-oriented programming, so a little ugliness in the later can be excused.
But one of the main advantage of Lua, is that it is very powerful for data representation. So you could replace all the XML data by Lua data, which will allow more flexibility, such as data fields that could be filled by either values or functions. Some example:
Obviously having all these fields which can be either values or functions would require some overhead before using them (checking which they are), but the added functionality is huge.
(Yes, Python can do the same, but the whitespaces are even more of an issue when the goal is simply to represent data.)
One vote for Fortran 77.
As one who had to deal with Fortran 77: awesome! The more people to share the pain, the better!
As far as I can tell, Lua can only have one 'module' per interpreter and they would be kept separate. It does not seem to have much capability in loading lots of scripts and would need help from the application (both for static loading at start up and dynamic loading... it has better capabilities in its library fro dealing with C modules that other Lua scripts).
AngelScript supports the inclusion of multiple script files when building a module and dynamically importing functions from other modules (Binding them is left to the application, though you can name which module it should come from in the script).
That's exactly what I was thinking
Boost.Phoenix version 3. A library to allow for functional programming in C++ (functional programming being where everything is a function, you likely meant procedural). Currently it is in beta and not availible.
Once you have learned one langauge, learning the others is not that hard.
And learning a langauge is the easy part if you are going to do more than simple data manipulation.
I've only done scripting in obscure languages, so I can't compare between the two. My understanding is that Python is more geared towards larger projects, while Lua is better for smaller ones. Whichever one is used I'm going to be spending considerable time learning and using it, so I hope it's a good choice.
Admittedly I have been tinkering with Python lately, but that's just in anticipation of the APIs being released. As for the whitespace - imo that's how code is supposed to be indented anyway, complaining about that seems like complaining about not being able to be sloppy.
What proper indenting is a subject of debate in langauges where it is merely cosmetic as some find certain ways of doing it more readable. And forgetting a tab should not be able to cause issues.
Choosing between Lua (Portugese for The Moon, not LUA) and Python is pretty easy for me. While Python is a good language with a lot of libraries and documentation I find it much easier to use the smaller orthogonally designed multi paradigm Lua with the ability to support both functional and object oriented programming (both prototype and class based) as well as imperative programming. Admittedly Python is pretty pragmatic too when it comes to that but with some strange exeptions. Never understood the rumor that Lua wasn't applicable for large scale projects.
Other pluses for me is the Lua mailing list, the superb interpreter code base and if speed ever becomes an issue the big ace in the hole that is LuaJIT.
I am not one to argue for sloppiness so much as robustness. While many of the obviously professional developers are making a strong case for the power of Python, I do not think that was ever in question.
It sounds like Lua would be the more forgiving / robust language for people without formal CS training / dev experience and those weekend coders who understand it, but do not live it. ( THATS ME )
Better multi-threading is great, but I am never going to try and implement that, and I do not think the majority of modders want to (just too complex for a hobby project). Given that this will be used primarily by people engaged in hobby projects versus full on development efforts, would you still argue as strongly for Python on the scripting side? )
Errr... I always confuse functional and procedural. Yep I meant procedural...
However better multithreading will make it easier for the application to keep the scripts from messing up because of it. The threading will likely be the application calling scripts from multiple thread rather than the scripts actually doing multi-threaded work on their own.
If one considers mulithreading a must then Python is pretty much dead in the water from my perspective.
Meh, I only noticed because last night I skimmed through the documentation of the library I mentioned. They are almost the same thing, just functional takes it to an extreme.
You are correct that simple procedures is most of what scripting will be for, so my samples on the first page give a good comparison of them. And dynamic typing vs. static typing is the only major diffrence (static being AngelScript and C++).
For those of you suggesting C++....are you serious? Do you not understand how unfriendly this language would be to someone who has little or no prior modding/programming experience?
Given Elemental's....unique...release circumstances the last thing it needs is C++ as its modding language. Whatever language is chosen, it needs to be *accessible* and easy to use. Python and LUA fit this requirement perfectly. Modding may be the one thing that might change Elemental's negative perception over time. Burdening the already thinned fanbase with learning C++ would seem like some sort of sick joke.
Also, it would be nice if we could get some concrete examples of how much of the game players will be able to change with modding. This might give us a better idea of what language is best suited for modding.
I know, I have fairly proficient knowledge of Java. But as a number of classes at my school use Python, and none use Lua, I'd rather put effort into learning a language I would use outside of Elemental. Of course, I wouldn't expect Stardock to make a choice just from what would be better for me...
Yes, do to the global lock it would be too slow if the application tries to run many scripts at once. And since Elemental is multi-threaded proformance with multiple threads matters.
Then you should promote AngelScript; the most major thing to learn transitioning to it from Java is that 'static' varaible and funtions can be placed outside of classes and have static left off.
There are many great features available to you once you register, including:
Sign in or Create Account