Why use lua?......

Started by
15 comments, last by pinacolada 15 years, 8 months ago
Hey guys, I figured I had something relevant to say on the Lua subject.

After just completing a project where i used Lua/Luabind for all of my Ai behavior; I come away saying that there is no way i would use it again. The major problem that i wasted at least a week of development time on (three weeks total development time) was stupid errors. When i think about it, its more of a Luabind problem, but what a problem it was.

I couldn't debug line to line and when the script did run into a problem it threw an error that told me nothing except that there was something wrong. The amount of time it took to hunt down these errors was disgustingly bad.

Writing the same code in C++ I would have had compile-time error checking, faster code (the game started to lag nearing the end of dev.) and if it did break at run-time, I would have been told where and why it had broken. All for a little more compiling.

/endRant

I guess the thing to take away from this post is to be wary of not nessacerally Lua but definitely Luabind.

Advertisement
Quote:Original post by Trandafira

I couldn't debug line to line and when the script did run into a problem it threw an error that told me nothing except that there was something wrong. The amount of time it took to hunt down these errors was disgustingly bad.


Quote:I guess the thing to take away from this post is to be wary of not nessacerally Lua but definitely Luabind.


It helps to implement your own stack walker for this very case. Given high level of meta data in LVM, that's somewhat trivial to achieve.

The same is true for other VM-based systems, where errors can be reported reliably and with adequate information, perhaps even full VM state dump.


The problem with run-time detection of errors however remains, but that can go either way, as a benefit or a problem.
Thanks for the replies.

Trandafira..bit worried with what your saying, so i will hold off using it for my current project, think i will use txt files that people can edit and write some code that interprets these txt files.

example --

say i include a file called change_character_name.txt in a mods folder somewhere in the application directory.

then the user can open it up and add a line of text like...

"boogieman" change_to "monsterman"

of course there would be a help file somewhere with a list of acceptable syntax.

As for game constants i have written a c++ program that does that instead.

Still WOW wouldn't be using lua if it didn't offer something over txt files.
Quote:Original post by gameplayprogammer
Thanks for the replies.

Trandafira..bit worried with what your saying, so i will hold off using it for my current project, think i will use txt files that people can edit and write some code that interprets these txt files.

example --

say i include a file called change_character_name.txt in a mods folder somewhere in the application directory.

then the user can open it up and add a line of text like...

"boogieman" change_to "monsterman"

of course there would be a help file somewhere with a list of acceptable syntax.

As for game constants i have written a c++ program that does that instead.

Still WOW wouldn't be using lua if it didn't offer something over txt files.


That solution sounds much worse.. you'll have all of the problems that Trandafira mentioned plus more. Plus it's a huge time sink. But anyway, have fun.
Quote:Original post by Trandafira
I guess the thing to take away from this post is to be wary of not nessacerally Lua but definitely Luabind.


The other thing to take away is your inexperiance with Lua vs C++.

Lua has a very complete debugging system; allowing for callbacks when the VM executes lines, when functions are called and return and after a specific number of VM instructions. It also has a very complete introspection library allowing for you to inspect the state of the VM during debugging.

That said, I wouldn't be surprised if most people ignored Lua's debugging system so you aren't alone here. However properly intergrated it can be a very useful tool for tracking down and debugging errors in your code.

As for the speed of the code, well this is where profiling comes in and if you discover a slow down you can always bring the code up into C or C++ for the speed boost. However it is always going to be easier going from Lua to C++ than the other way around.
pinacolada, i think you need to read Trandafira post again.

Trandafira wrote
"Writing the same code in C++ I would have had compile-time error checking, faster code (the game started to lag nearing the end of dev.) and if it did break at run-time, I would have been told where and why it had broken. All for a little more compiling. "
Yeah I know. You said your plan was to "use txt files that people can edit and write some code that interprets these txt files." So essentially, these text files are going to be really simple scripts.

Are you going to have compile-time checks that verify that these files are properly written? If an error is caused by something in one of these text files, are you going to have something that prints what line the error occured on?

And if your answer is, "I won't have to worry about that because these scripts will be really really simple", then I'd say, you can also avoid those problems if you write simple scripts in Lua. And you won't have to spend time writing a parser and an interpreter.

[Edited by - pinacolada on July 31, 2008 12:08:12 PM]

This topic is closed to new replies.

Advertisement