View topic - Why Lua?



All times are UTC + 1 hour


Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Why Lua?
PostPosted: 22 Apr 2010, 21:28 

Joined: 19 Apr 2010, 14:31
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?


Top
 Offline Profile  
 
 Post subject: Re: Why Lua?
PostPosted: 22 Apr 2010, 21:37 
User avatar

Joined: 23 Oct 2004, 00:43
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, 21:40, edited 2 times in total.

Top
 Offline Profile  
 
 Post subject: Re: Why Lua?
PostPosted: 22 Apr 2010, 21:39 
Community Lead
User avatar

Joined: 10 Apr 2006, 04:05
Location: Finland, 1944
Additionally, Lua is less formidable to the beginner.


Top
 Offline Profile  
 
 Post subject: Re: Why Lua?
PostPosted: 22 Apr 2010, 22:01 

Joined: 19 Apr 2010, 14:31
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.


Top
 Offline Profile  
 
 Post subject: Re: Why Lua?
PostPosted: 22 Apr 2010, 22:03 
User avatar

Joined: 23 Oct 2004, 00:43
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.


Top
 Offline Profile  
 
 Post subject: Re: Why Lua?
PostPosted: 23 Apr 2010, 07:45 
Spring Developer
User avatar

Joined: 22 Sep 2007, 08:51
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.


Top
 Offline Profile  
 
 Post subject: Re: Why Lua?
PostPosted: 23 Apr 2010, 12:02 
AI Coder
User avatar

Joined: 14 Sep 2004, 10:32
Location: Cookieland
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.


Top
 Offline Profile  
 
 Post subject: Re: Why Lua?
PostPosted: 23 Apr 2010, 13:29 
Spring Developer

Joined: 01 Jun 2005, 10:36
Location: The Netherlands
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.

Quote:
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...)

Quote:
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.


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Site layout created by Roflcopter et al.