Why use lua?......

Started by
15 comments, last by pinacolada 15 years, 9 months ago
i was looking to generate .h/.cpp files that stored my game constants and some utility functions. I was going to write a c++ application that did this for me and put the files in the source code directory. I notice that alot of games companies use lua, so i thought it would be good to get experience using it. After looking at the syntax i am wondering, why use it? Is it for people who don't know how to write c++? Is it to decrease build times everytime you change something in code? Any industry veterans out there explain why it is in wide spread us....
Advertisement
sorry, should say "wide spread use...." :-)
Lua is a scripting language.

Scripting languages are used to create program sequences beside the sequences you build in C. They are compiled on the fly, which means you can simply change the scripts and rerun the applications without the need of a compiler or linker. It also enables that you have a scripter and a programmer working seperately.

Scripting languages are less efficient, so don't use them for heavy loops, but for GUI's or w/e kind of effect / AI you can use it easily.

Only problem I find is binding it with C, but I've seen some variations on Lua that had better? bindings with C / C++.

PS: another point, a MOD community can easily make mods with scripts! :)
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
Quote:Original post by Decrius

Scripting languages are used to create program sequences beside the sequences you build in C. They are compiled on the fly, which means you can simply change the scripts and rerun the applications without the need of a compiler or linker.


You can change scripts while the application is running. The need to restart is suboptimal.


This enables trial-and-error coding. Many "programmers" can hack-and-slash together pretty useful pieces of code (see script kiddies), but the process of formal software development represents a huge barrier to entry for them.

Another advantage is that these languages tend to be error-tolerant, and are devoid of almost all CS concepts (memory management, data structures, algorithms). Script languages are generally also well suited for copy-paste coding.

If the interface between scripts and application is solid, then scripters will have really hard time breaking anything, while still getting solid results.

Perhaps the most prominent example of this is the wow add-ons, which also puts realistic performance of scripting into perspective.
I really prefer python, the only problem with python is that you can VERY EASILY make malicious scripts
Quote:Original post by arthurprs
I really prefer python, the only problem with python is that you can VERY EASILY make malicious scripts


How is it easier than with Lua?
Lua is actually really easy to sandbox, because of the relatively explicit order-of-loading. You can wrap the standard library with your sandboxing code before loading any more scripts into a lua context, and do things like install checks against opening files outside of the game data directory, or even remove the standard library file library completely, and provide only your own data and registry API to the script.
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
Quote:Original post by Antheus
Quote:Original post by Decrius

Scripting languages are used to create program sequences beside the sequences you build in C. They are compiled on the fly, which means you can simply change the scripts and rerun the applications without the need of a compiler or linker.


Another advantage is that these languages tend to be error-tolerant, and are devoid of almost all CS concepts (memory management, data structures, algorithms). Script languages are generally also well suited for copy-paste coding.


I do not agree with your assesment there. I was just looking at the wiki page and it lists the following: first-class functions, garbage collection, closures, proper tail calls and coroutines. It also has the map as its basic data structure. These are certainly CS concepts and exposed far more cleanly and graspably than in C++ (which can only emulate most of these CS concepts with its powerful template programming system).
Quote:Original post by Daerax

I do not agree with your assesment there. I was just looking at the wiki page and it lists the following: first-class functions, garbage collection, closures, proper tail calls and coroutines. It also has the map as its basic data structure. These are certainly CS concepts and exposed far more cleanly and graspably than in C++ (which can only emulate most of these CS concepts with its powerful template programming system).


Of course you can use some of the advanced concepts.

But consider the typical C#, Java model. First, there's interfaces vs. classes. Then there's List and Iterator (Enumeration, and similar) concepts. Then there's various foreach vs. for iterations, there's the pass by value vs. pass by reference (depending on language), and much more...

For programmers, that's utopia. But all of this is completely redundant from scripting perspective.

Consider the "object" as dictionary concept.

player = {}
player["health"] = 100
player["mana"] = 100
player["quests"] = {}

None of the:
public class Player implements Comparable, Serializable {  private long UUID = 0x44297862357860348; // or whatever goes there  private int health = 100;  private int mana = 100;  public int getHealth() { return health; }  public int getMana() { return mana; }  public boolean equals(Object o) {    // LOTS of code  }  public int hashcode() {   // LOTS of code  }  public String toString() {    return "Mana: " + mana + "health: " + health + ....;  }  }


Neither of the code is exactly correct, but in first case, there's absolutely no mental overhead. You-code-as-you-think. In later case, everything bold is just implementation details.

Granted there's limitations. But for many users, the benefits of more structured languages are just redundant.

This is part of the reason why Python has been gaining momentum.
I agree with that but my disagreement - that they do not allow much ("devoid of almost all") CS - has not changed. For the same reasons you mention you can introduce CS concepts with little overhead in a scripting languages. Theres nothing stopping you from using CS concepts when using a scripting language, it makes programming in them even more effective. The tools are present. That even handedness is what makes them good, lenient for the beginner, advanced enough for an experienced person.

I Mean being forced to type all that boiler plate does not make it proper programming in my eyes. Imagine if you had to solve a large set of non linear partial differential equations in thousands of variables every time you had to walk or shoot a basketball. Abstractions are useful to everyone, expert programmer or casual scripter.

Id place python above a mere scripting language. It is a quite expressive programming language. Python is so popular because of it is freely typed nature, adoption of lots of modern CS features and its powerful reflective capabilities. It is because of these reasons that you can code off the top of your head seemingly. But you can also do some really advanced 'C.S. c' things in it though the style seems to still be based around trial and error err 'tests'. Though I wonder how well it scales for large projects.

This topic is closed to new replies.

Advertisement