Jump to content
  • Advertisement
Sign in to follow this  
gameplayprogammer

Why use lua?......

This topic is 3707 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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! :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!