Jump to content
  • entries
    38
  • comments
    119
  • views
    87,391

Even Faster


Canardia

8,216 views

 Share

People are wondering what language they choose with Leadwerks3D. Sometimes they have some exotic languages in mind, but quite often it comes down to the decision between Lua and C++.

 

Recently I read an article that LuaJIT (yes, you can use it in Leadwerks3D too) is actually damn fast. It's fast, because the simpliness of the language allows for extreme optimizations. It might even come close to C++ speed, or in some cases even exceed it. That's how fast LuaJIT 2.0 is. But it's still in beta, so it can only get faster.

 

Same goes for Fortran 2008 btw, it usually beats the speed of C++, because the compiler knows which CPU registers are in use and can assign them intelligently, which C++ can't, since it doesn't know which registers are in use. But it doesn't have such nicely optimized STL libraries for linked lists and stuff, so it ends up slower in those cases, because nobody can single handed make such great optimizations as STL provides.

 

Lua has some advantages and also disadvantages over C++.

 

The advantages are:

1) You can use the same code on all platforms, which makes finishing your game much faster

2) You can develop in real time, because you only need to compile for the final release of the game, if even then, but usually you will need it if your game does some more complex calculations, and to make sure your game runs also well on slower machines

3) You can learn it much faster than C++, it's really just basic, and often even easier than that because there are no types and other annoying stuff

4) You can share code with other people much easier, because like beforementioned, nothing is type specific, which allows for extreme abstraction and generic code

 

The disadvantages are:

1) You don't have such great arsenal of 3rd party libraries ready for Lua, although with some effort you can find some libraries which someone has made, or you can take any C/C++ library and wrap it yourself for Lua

2) If you really need maximum speed for some time critical routines, you still need C. Yes, not even C++ is fast enough for those. And then you need to wrap them again for Lua

 

For reference, here is an article that LuaJIT can actually even come on par with C in some benchmarks:

http://lua-users.org...6/msg00071.html

 

On the other hand, I think with the growing interest for Lua in Leadwerks3D, the Werkspace asset store will provide more and more ready made libraries for Lua over time.

 

My conclusion is, that LuaJIT 2.0 is a very easy and fast alternative to C++ with Leadwerks3D, and it allows also sharing of code and code snippets much easier than C++ does. Which is what the Leadwerks Community is about.

  • Upvote 1
 Share

21 Comments


Recommended Comments

For anyone already familiar and skilled in C++ I can see no advantage in using Lua other than as a simple scripting language. To have the game engine framework and mechanics written in C/C++ and the game logic and AI scripting implemented in Lua seems ideal and makes full use of the underlying benefits of each language.

Link to comment
I can see no advantage in using Lua other than as a simple scripting language.

 

I think when people always refer to Lua as being used as a "simple" scripting language it turns people off. Some of the interactions for game logic and AI scripting can and will most likely be anything but simple and can very often be the bulk of the game code.

 

One main advantage I can think of in terms of LE is the ease of running on multiple platforms. I don't know if you've tried compiling for Android devices, but it's a complete pain in the bum. I'll gladly lose 10 fps to not have to deal with that. I really like the idea of not having to recompile my game 4-5 times for each platform because there is bound to be issues.

 

The other advantage, although I still don't think LE3D will take full advantage of, is the sharing of components is easier. I'm familiar with C++ and I do enjoy using it, but Lua is easier to share IF the structure is there in the game engine to support it.

 

For a lot of the mobile games that will for sure come out of LE3D, Lua will work perfectly for the entire game. Most indie games on the market don't really push the boundaries of PC's or GPU's so Lua works well to get them going fast.

 

I personally prefer the syntax of C++ myself and I like having actual types, but there can be advantages for using Lua for an entire project.

Link to comment

LUA is very nice, and unfortunatelly, scripting language too, what is a major disadvantage, from my standpoint..also, as pixel said, for anyone who has slight idea about C++, LUA is not a good way to go..dont get me wrong, Im NOT saying that you cant finish game with LUA or anything like that..im not even saying that LUA is slow or anything performance wise..all im saying is that, from self investment standpoint, for along run, you stand better if you take C++ route (I say C++ because it was mentioned here, but when LE is in case, Im favorizing BMax all the way)...

Link to comment

Uncompiled Lua beats even Java in speed, so I bet it beats BlitzMax too. But then LuaJIT, the compiled Lua beats everything else, with a few exceptions like I described above.

Link to comment

Uncompiled Lua beats even Java in speed, so I bet it beats BlitzMax too. But then LuaJIT, the compiled Lua beats everything else, with a few exceptions like I described above.

..then i have to conclude that you havent seen well written Java or BMax code..

Link to comment

You have to remember also that coding in Java is a horror. You find some example on google, but nobody cares to mention what import libraries you need to do. Usually finding the right import libraries takes longer than actually coding the whole thing in C++ or Lua. In some other article I actually read that Java is slower than interpreted Lua, that's why I mentioned it. I don't know how BMax compares to Java, but I would guess it's about the same speed. You just can't keep up with speed with GC languages, they are doomed to death.

Link to comment

Lua is a pretty standard scripting language just like C++ is a standard programming language so having both or either will be valuable for anyone for other real world job opportunities. Game companies will hire scripters (not full blown programmers) as well because you can often pay them less.

 

I believe C++ and Lua are the 2 best combinations for real world job opportunities in programming and scripting for games. For business it's Java and .NET hands down.

  • Upvote 1
Link to comment

You always take my comments completely out of context Rick. I said and I quote

 

For anyone already familiar and skilled in C++ I can see no advantage in using Lua other than as a simple scripting language.

 

not

 

I can see no advantage in using Lua other than as a simple scripting language.

which completely changes the meaning of the sentence. I don't understand why you do this!

Link to comment

Generally if I take something out of context in a quote it's because I personally feel a certain part has no merit. I should maybe explain that in my postings but I guess I just keep it in my head smile.png.

 

I felt that the "For anyone already familiar and skilled in C++" has no merit in the statement. I know C++, and I was listing reasons why Lua has some advantages over it (agree to disagree sort of thing). In all honestly even if you put the knowing C++ part in, it doesn't change the fact that statements like that can be disagreed with (which I was trying to do and list reasons why). That was the general message of my post. That in my argument knowing C++ already, has nothing to do with altering ones view on how or when to use Lua in making a game. Again, that's the agree to disagree part as full games have been made with both langauges, no right answer can be found.

 

So it's not that I'm taking your posts out of context, I just decided to omit why I quoted a certain part. I was trying to list why the first part of your comment has nothing to do with the last.

 

Basically I'm arguing your whole statement, without quoting your whole statement but keeping your whole statement in my head while making my argument. If that makes sense.

 

So it's not that my explanation took your quote out of context, it's just that I didn't quote your entire statement before I gave my argument. My explanation does list why knowing C++ already doesn't mean there aren't advantages to using Lua other than a simple scripting langauge, in where your entire statement was you couldn't find any if you already know C++.

 

I hope that makes sense because that's how it went down in my head :D

Link to comment
@Paul

..good one..nuff said smile.png ..

 

That chart actually seems to point out Lua JIT with JIT turned on or off is faster in certain situations than a good number of languages and very comparable to C in some situations.

 

In my view run-time speed is not the end all be all. Very few indie people are actually pushing the speed limits. Most indie games are pretty basic. I still think on pure count alone on advantages Lua beats C/C++. Then it comes down to how you weight advantages/disadvantages.

 

Again, I love C/C++. I love it's syntax, but I can't argue with the number of advantages. I'm pushed myself to do both in LE and this is my findings. If others have actually given both a real try in LE I'd be curious to hear their opposing thoughts, but there doesn't seem to be to many of the mixed Lua & C/C++ crowd out there.

Link to comment
I felt that the "For anyone already familiar and skilled in C++" has no merit in the statement.

I know C++, and I was listing reasons why Lua has some advantages over it (agree to disagree sort of thing).[/Quote]

Advantages exist for just about everything you care to look at in life, but people don't base informed descisions on advantages alone, it requires a much more balanced weighing up of both advantages and disadvantages.

 

I stand by what I said and, within my full statement, there was never any inference that Lua couldn't be used to develop a whole game. However, the cut down sentance you posted would imply just that to most people reading it. Neither did I mean to imply that AI or game logic was neccessarily simple, but that Lua was simply being used as a scripting language in this context.

 

The use of Lua as a scripting language to code the 'game' as opposed to the 'game engine' which was what I was advocating brings about the major advantage you've cited for Lua anyway, namely no need to recompile during the game development cycle.

 

I have no problem with you disagreeing with anything I say Rick, that's your prerogative and I'm open to a convincing argument anyway. But I dislike being miss quoted, as that is no longer a true representation of what I said, regardless of whether you think the rest of it was relevant or not!

Link to comment
However, the cut down sentance you posted would imply just that to most people reading it.

 

I agree someone would have to have read my whole comment to see that I did include the C++ part of your statement in the arument itself and that I didn't quote the entire thing. I'll try to quote entire things from now on, or just leave the quotes out and let people figure out the context for themselves as they read the entire thread. Sorry for that, it's just lazy and implied quoting on my part. Honestly it's exhausting sometimes trying to give arguments in text as you have to cover your butt so much as to not offend or leave gaps. I much prefer in person smile.png

Link to comment

You should always put ... in front and/or after a sentence part, if you don't quote the whole sentence. But you should never cut out parts which negate or change the meaning of the quoted part.

Link to comment

Sorry for that, it's just lazy and implied quoting on my part. Honestly it's exhausting sometimes trying to give arguments in text as you have to cover your butt so much as to not offend or leave gaps. I much prefer in person smile.png

That's ok Rick. I wasn't implying you had deliberately set out to misrepresent what I'd said. It's not always easy when replying quickly on forums and I'm sure I've probably done the same in the past.

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...