Why Lua?

Why Lua?

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

Post Reply
discodowney
Posts: 47
Joined: 19 Apr 2010, 15:31

Why Lua?

Post by discodowney »

Im curious why Lua has taken off so much, especially on here it seems used in loads of the AI's. Im currently reading about it and im just wondering what is so special about it? Is it just the general ease of use or is there ways to reduce determinism of the AI with it?
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Why Lua?

Post by Pxtl »

discodowney wrote:Im curious why Lua has taken off so much, especially on here it seems used in loads of the AI's. Im currently reading about it and im just wondering what is so special about it? Is it just the general ease of use or is there ways to reduce determinism of the AI with it?
I think a big reason is that Lua works so much better with the Spring engine. C++AIs have been a colossal pain in the butt since day 1 - they crash and take the whole engine down with them, they don't filter on which mods they know how to support, etc. A Lua AI does none of those things - you have to really work at it to crash the engine with pure Lua logic (infinite loops and whatnot). They can be bundled in the mod SD7 and thus be kept up-to-date with the mod seamlessly instead of being distributed as a separate package.

Plus it's better security for hte end user. Realize that all the users of the Spring engine are running untrusted code from unknown sources. It is almost undoubtable that somebody could write an exploit in Lua that would allow you to take over the player's machine, but the source would be plainly visible and it would take some tricking (ie. buffer overruns) of the engine to unlock this potential. Native C++ has none of those - the source is hidden through compilation, and you have direct access to the user's computer.
Last edited by Pxtl on 22 Apr 2010, 22:40, edited 2 times in total.
User avatar
Neddie
Community Lead
Posts: 9406
Joined: 10 Apr 2006, 05:05

Re: Why Lua?

Post by Neddie »

Additionally, Lua is less formidable to the beginner.
discodowney
Posts: 47
Joined: 19 Apr 2010, 15:31

Re: Why Lua?

Post by discodowney »

Cool. Ive only read a bit, but is there any pros in the gameplay column for lua, or is it mostly as you mention above, for technical reasons?

Edit - whoops! skipped over the last comment. Okay so it is used to make more casual friendly AI, for lack of a better term.
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Why Lua?

Post by Pxtl »

discodowney wrote:Cool. Ive only read a bit, but is there any pros in the gameplay column for lua, or is it mostly as you mention above, for technical reasons?
All Turing-complete languages are logically equivalent. Thus, any gameplay concept you can express in Lua can be expressed in C++ and vice-versa. Lua will be easier to do it in, probably, but C++ will give faster performance if used correctly.... but that would only be a concern if you've got some really processor-intensive crap planned.

So from a gameplay perspective, all programming languages are identical.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Why Lua?

Post by hoijui »

well, that is not really correct, please be fair or shut up if you have no idea. RAI, KAIK and AAI are very stable these days, and E323AI is also much better then what you make it sound. E323AI also uses special algorithms, which make it so good at harassing, which already use tremendous CPU time, so it definitely makes sense to have native AIs.
additionally we have Java AIs, which can not crash the engine (except there is a bug in the engine). plus, what you describe as a pure pro (mod bundled-ness of the AI), is actually a negative for the AI dev, if he is not closely related to the mod devs himself.
As AF already told you in other threads, it is also possible to write a native AI interface and use Lua on top of that, which he did with Shard in C++, and it seems to work fine.
The JVM supports many scripting languages, which you can use directly as language for your AI, though the Java AI Interface.

All this said, i wont argue against that you may really be off best using Lua for your AI, either directly or through Shard, as you want to keep everything simple.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Why Lua?

Post by AF »

Hoijui is right but he misses out some further points:
  • You cant use buggyness and crashing as a criticism of native AIs, because it can be avoided by crashing gracefully. Some native AI developers are of the opinion that it is actually good to crash the whole engine, not bad, because they get error reports. Which I think is irresponsible of them and unfriendly to the end user.

    An example of crashing gracefully being NTai. When NTai crashed, it caught the crash and logged it to a file, and sometimes would continue to play the game as if nothing had happened.

    The same is true of Shard. If Shard runs into a fatal error, it prints a stack trace to the console and carries on as if nothing happened. Sure if its at the very beginning the commander will sit still, or it might cause odd behaviour, but the game wont end, and your told exactly what happened, and you can choose for yourself what your going to do.
  • Lua AIs crash too. Just because it didnt crash the engine ( and it can), doesnt mean the AI will still work, what caused a crash on frame 5, is still there on frame 6, and your likely to have a half functional or nonfunctional AI that spams the console with errors
  • Security is a load of bullsh*t. There's nothing stopping someone from compiling their lua code with a standalone lua executable, and then loading it in via a widget. Just because so far nobody has bothered to do it and put it all in plain text, doesn't mean it cant be done.
I'd have thought the whole riff raff of native vs lua would have been dead in the water after I released Shard, an example of an AI that crashes gracefully and can pick itself up again and continue playing, that has the benefits of native AIs, while having the advantages of a dynamically typed language.

There are only 2 advantages to pure lua AIs in this engine. Yes ONLY 2:
  • They can be bundled in the archive
  • They allow better integration with Lua Rules
Both of which are also disadvantages, and have major downsides, for example:
  • Bundling with an archive is anticompetitive
  • It encourages tighter integration, and thus, sloppy code, as API design and architecture aren't taken into account
  • Updates to the AI require a re-release of the entire game and a version bump
  • A half decent content developer packages his mod up in an installer, thus negating the advantage of bundling AIs in the archive
  • Native AIs can read their data from the VFS and override it with unsynced data saved in local storage
  • It discourages defining proper APIs and mechanisms for interacting with custom game rules.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Why Lua?

Post by Tobi »

AF wrote:
  • Security is a load of bullsh*t. There's nothing stopping someone from compiling their lua code with a standalone lua executable, and then loading it in via a widget. Just because so far nobody has bothered to do it and put it all in plain text, doesn't mean it cant be done.
And then?

It can't do much more than block Spring using an infinite loop or allocate infinite memory or so, whereas a native AI has full access to everything the user has access to, so it can wipe all your files, install trojans, etc.
Updates to the AI require a re-release of the entire game and a version bump
No reason a game would require a full re-release on an update to a Lua AI. The only real disadvantages here are:
  • It's impossible to make an AI that, when installed, is only a single file. Not much native AIs have this property either, though (only KAIK?).
  • It has a worse user experience when the AI is separate (Need to pick the AI mutator for the game to be able to add the AI...)
Bundling with an archive is anticompetitive
A half decent content developer packages his mod up in an installer, thus negating the advantage of bundling AIs in the archive
So both Lua AIs and native AIs are equally anticompetitive for half decent content developers. Additionally, when a native AI is bundled you need full re-release on an update to the native AI too. (except when it is self updating, but I've yet to see that implemented [in a safe and cross-platform way])

A third major advantage of Lua AIs is that they need no compiling and work on all platforms on which Spring works. This doesn't apply to native AIs.

I agree with the other points, although IMO adapting to custom game rules and implementing APIs and stuff other than those which apply to the target game(s) may be a waste of time if the goal is simply to make a reasonable AI in the shortest amount of time possible.
Post Reply

Return to “AI”