It's all in your head, Part 9

The only place you'll ever hear the truth
User avatar
shinygerbil
level5
level5
Posts: 4667
Joined: Wed Dec 22, 2004 10:14 pm
Location: Out, finding my own food. Also, doing the shinyBonsai Manoeuvre(tm)
Contact:

Re: It's all in your head, Part 9

Postby shinygerbil » Sun Feb 17, 2008 7:19 pm

Pox wrote:
KingAl wrote:
shinygerbil wrote:
skull13 wrote:I have barely heard of Python
I think you are in the minority there. ;)


As a point of reference. I don't think the deciding issue will ever be popularity.


Epic up arrows for LUA :shock:


java at the top :x :x :x
Here is my signature. Make of it what you will.
Image
User avatar
briceman2
level2
level2
Posts: 123
Joined: Wed Dec 12, 2007 4:30 am

Postby briceman2 » Sun Feb 17, 2008 8:19 pm

several people wrote:LUA is specifically designed for game scripting


Uh, this is just Wrong with a capital W. Lua started out as a research language. After it hit v4.0 it began to become popular as an embedded scripting language. I don't know when the first game used it, but I'll bet my teeth it wasn't back in 1994.

Lua 1.1 was released on 08 Jul 1994. This was the first public release of Lua and is described in a conference paper. Lua 1.1 already featured powerful data description constructs, simple syntax, and a bytecode virtual machine. Lua 1.1 was freely available for academic purposes; commercial uses had to be negotiated, but none ever were.


From the 1996 Dr. Dobb's article: ( http://www.lua.org/ddj.html )

Lua: an Extensible Embedded Language
A few metamechanisms replace a host of features

by Luiz Henrique de Figueiredo, Roberto Ierusalimschy, and Waldemar Celes

In recent years, a multitude of little languages have been proposed for extending and customizing applications. In general, these extension languages should have the following attributes:

o Clear and simple syntax (since it is not the main language for most of its users).
o Small size and small implementation (so the cost of adding it to the host will not be too high).
o Good data-description facilities (to make it useful as a configuration language).
o Adequate extensibility (to allow its use in high abstraction levels--for interfacing with users in diverse domains).

Since extension languages are not for writing large pieces of software, mechanisms for supporting programming-in-the-large, like static type checking and information hiding, are not essential.

Lua, the extensible, embedded language we present here, satisfies these requirements. Its syntax and control structures are simple and familiar. Lua is small--the whole implementation is less than 6000 lines of ANSI C. Besides the facilities common to most procedural languages, Lua has special features that make it a powerful high-level extensible language:

o Ability to define and manipulate functions as first-class values, which greatly simplifies the implementation of object-oriented facilities.
o Associative arrays--powerful language constructs that implement most data containers.
o Garbage collection, negating the need for explicit managing of memory allocations--a major source of programming errors.
o A fallback mechanism, allowing extension of the semantics of the language.
o Reflexive facilities, allowing the creation of highly polymorphic parts.

Lua is a general-purpose embedded programming language designed to support procedural programming with data-description facilities. Although it is not in the public domain (TeCGraf retains the copyright), Lua is freely available for both academic and commercial purposes at http://www.lua.org/.
User avatar
briceman2
level2
level2
Posts: 123
Joined: Wed Dec 12, 2007 4:30 am

Postby briceman2 » Sun Feb 17, 2008 8:42 pm

Chris wrote:Specifically id love to know if you used lua in a class based way with objects, methods, inheritance etc through metatables, or if you just used it by passing in object pointers to all your functions with no real OO programming.


In case you haven't found this yet, the online version of Programming in Lua ( http://www.lua.org/pil/index.html ) contains a chapter on OOP in Lua 5.1 which can be found starting here: http://www.lua.org/pil/16.html

16 Object-Oriented Programming
. 16.1 Classes
. 16.2 Inheritance
. 16.3 Multiple Inheritance
. 16.4 Privacy
. 16.5 The Single-Method Approach


Also check out LOOP ( Lua Object-Oriented Programming, http://oil.luaforge.net/loop/ ), which has some excellent documentation at http://oil.luaforge.net/loop/docs.html

The packages provided by LOOP are not intended to define a standard object-oriented model for the Lua language. Instead, the different models provided should be seen as examples of how to introduce more traditional object-oriented features into the language. Particularly, LOOP models are mainly concerned to dynamicity, although there is an attempt to keep them as simple and efficient as possible. Additionally, LOOP uses the fundamental Lua concepts like tables (objects) and meta-tables (classes), traditionally used to enable an object-oriented programming style, to provide a common ground for the interoperability of objects and classes from its different models.
User avatar
Pox
level5
level5
Posts: 1786
Joined: Sat Mar 03, 2007 11:23 am
Location: Melbourne

Re: It's all in your head, Part 9

Postby Pox » Sun Feb 17, 2008 9:26 pm

shinygerbil wrote:
Pox wrote:
KingAl wrote:
shinygerbil wrote:
skull13 wrote:I have barely heard of Python
I think you are in the minority there. ;)


As a point of reference. I don't think the deciding issue will ever be popularity.


Epic up arrows for LUA :shock:


java at the top :x :x :x


Mmmm... shows you that the popular aren't always the best. Or never, in this case... ewww, Java!

and briceman2: thanks for the enlightenment! I did think LUA was designed for game scripting, but looks like I'm dead wrong. Brilliant :D
User avatar
KingAl
level5
level5
Posts: 4138
Joined: Sun Sep 10, 2006 7:42 am

Re: It's all in your head, Part 9

Postby KingAl » Mon Feb 18, 2008 12:34 am

shinygerbil wrote:
Pox wrote:
KingAl wrote:
shinygerbil wrote:
skull13 wrote:I have barely heard of Python
I think you are in the minority there. ;)


As a point of reference. I don't think the deciding issue will ever be popularity.


Epic up arrows for LUA :shock:


java at the top :x :x :x


Visual Basic above C++ :lol: :lol: :lol:
Gentlemen, you can't fight in here: this is the War Room!
Ultimate Uplink Guide
Latest Patch
User avatar
Pox
level5
level5
Posts: 1786
Joined: Sat Mar 03, 2007 11:23 am
Location: Melbourne

Re: It's all in your head, Part 9

Postby Pox » Mon Feb 18, 2008 4:14 am

KingAl wrote:
shinygerbil wrote:
Pox wrote:
KingAl wrote:
shinygerbil wrote:
skull13 wrote:I have barely heard of Python
I think you are in the minority there. ;)


As a point of reference. I don't think the deciding issue will ever be popularity.


Epic up arrows for LUA :shock:


java at the top :x :x :x


Visual Basic above C++ :lol: :lol: :lol:


Mmm, shows how much attention we should pay to that there rankings. VB is exactly what the acronym stands for, BEGINNERS something something something symbolic code with shit on top.
ToxicFrog
level1
level1
Posts: 10
Joined: Sun May 02, 2004 7:40 am

Re: It's all in your head, Part 9

Postby ToxicFrog » Mon Feb 18, 2008 4:30 am

skull13 wrote:Chris, I have played many games using Lua scripts, and while I find these feats to be impressive (It's how Excalibur: Morgana's Revenge put vehicles in one level, Vendetta Online uses them for impressive plug-ins) I have never tried making a game of this scale. (I tried to make text games in Ruby, but they all flopped) The point is, many, many people know Lua and you will probably get a much larger mod community if you use that. (Of course, this is based on my experiences, several games I play use Lua for mods, but I have barely heard of Python)

It scales well, and as far big games using it goes - Homeworld 2, Spellforce, and Supreme Commander all use it heavily, SupComm probably most of all.

briceman2 wrote:In case you haven't found this yet, the online version of Programming in Lua ( http://www.lua.org/pil/index.html ) contains a chapter on OOP in Lua 5.1 which can be found starting here: http://www.lua.org/pil/16.html

5.0, actually. PiL 2nd edition covers 5.1, but isn't available online. The two versions are mostly compatible, though.

Uh, this is just Wrong with a capital W. Lua started out as a research language. After it hit v4.0 it began to become popular as an embedded scripting language. I don't know when the first game used it, but I'll bet my teeth it wasn't back in 1994.

Actually, if the Lua history page is accurate - and it should be - Lua was not developed as a research language; it was created to replace two earlier languages, DEL and SOL, for practical use. And while gaming was not a focus (it may not even have been a consideration), it was created as an extension language.
Lua 2.x was used in Grim Fandango in 1997; it may not have become truly popular game programming until version 4 (which overhauled a lot of stuff), but it was definitely in use for game embedding well before that.
User avatar
briceman2
level2
level2
Posts: 123
Joined: Wed Dec 12, 2007 4:30 am

Re: It's all in your head, Part 9

Postby briceman2 » Mon Feb 18, 2008 5:17 am

ToxicFrog wrote:Actually, if the Lua history page is accurate - and it should be - Lua was not developed as a research language; it was created to replace two earlier languages, DEL and SOL, for practical use. And while gaming was not a focus (it may not even have been a consideration), it was created as an extension language.


Thanks for the correction about the version covered in the online PiL manual!

I was going by the versions timeline ( http://www.lua.org/versions.html ). I called it a "research" language based on all the references to "academic" licensing in the early versions blurbs and the DDJ reprint. The radical reliance on visible tables to implement everything felt a lot like an academic experimental language when I first read the 4.0 reference manual long ago. The new ideas have certainly proved their worth (and flexibility) over the years.

However it started, I think it's clear it was not designed primarily for extending game engines. IIRC one of the prime focuses was to make it as lightweight as possible... for all those times when you don't really need to bolt a universal swiss army knife (perl) or the whole kitchen plus sink (python) onto your app. In the DDJ article they say, "Lua is small -- the whole implementation is less than 6000 lines of ANSI C." (That would have been either v2.4 or v2.5.)

To me, it's design philosophy seems a lot like that of Forth. Just enough tools to let you build your own tools, and as few restrictions (and/or as much flexibility) as possible. It's still close to the metal like C, and requires you to understand a lot of low level implementation details, but it's a heck of a lot more friendly than Forth ever was!
User avatar
Dark Phoenix
level1
level1
Posts: 34
Joined: Wed Jun 23, 2004 12:53 am
Location: Infernal Battlefields of Acheron

Postby Dark Phoenix » Mon Feb 18, 2008 11:36 pm

Wow, I haven't posted here in a while. Regardless, I think that either language would probably be good, though I, personally, much prefer Python. I find it to be one of the most elegant languages I've used - definitely more so than C/C#/C++, Java, or Perl (not to mention Ruby... Oh, god, what an ugly language that is) - maybe the most elegant I've ever seen aside from Lisp/Scheme ("these were your father's parentheses..."). The indentation-based interpretation doesn't take that long to get used to, and the benefit is that it's practically impossible to write unreadable spaghetti code in Python. Lua looks interesting, but I personally don't like the way the code looks, and the idea of having to code objects as tables annoys me to no end - there's a reason OO programming has gained the popularity it has, and to make people essentially use hacks to simulate that is inelegant and stupid in my opinion.

On the other hand, Lua is light, fast, fairly elegant, easy to embed, and has very good community support. So I'd argue for you to take your pick.
"There is no idea so good it can't be ruined by a few well-placed idiots." - Scott Adams,
creator of "Dilbert"

Sometimes you're the bug, and sometimes you're the windshield.
ToxicFrog
level1
level1
Posts: 10
Joined: Sun May 02, 2004 7:40 am

Postby ToxicFrog » Wed Feb 20, 2008 7:47 pm

Dark Phoenix wrote: Lua looks interesting, but I personally don't like the way the code looks, and the idea of having to code objects as tables annoys me to no end - there's a reason OO programming has gained the popularity it has, and to make people essentially use hacks to simulate that is inelegant and stupid in my opinion.

As you're a Schemer, this statement surprises me. Scheme doesn't supply OO constructs either - it gives you some basic components (the list, primarily) from which you can build more complex, powerful, and abstract features. Is that hackish, inelegant, and stupid?
Lua takes a similar approach, just with the associative table as the basic structured data type rather than the list. From that, you build whatever you need.
User avatar
Dark Phoenix
level1
level1
Posts: 34
Joined: Wed Jun 23, 2004 12:53 am
Location: Infernal Battlefields of Acheron

Postby Dark Phoenix » Sat Feb 23, 2008 9:44 am

I agree, Scheme doesn't supply OO constructs, but it also happens to be primarily an algorithmic, functionally recursive language, not an object-oriented, data structure-driven one. Though I said it was elegant, and I love the language, it's still not something I would use for event/object/entity scripting like in a game, largely because it doesn't (easily) support nice OO features. With this in mind, Lua seems like more of a hack to me in terms of the way in which it's used - for game scripting, which IMO is best done using objects. Having to essentially bootstrap objects from association tables does not sound like my idea of fun. Not to mention I greatly prefer Python's syntax to Lua's (as a friend of mine put it, "yes it's more embeddable, but it's not Python. Python is God's language.").

I would not, however, mind using Lua that much if it happens to be what Chris finally decides on. It is, after all, a perfectly useful, fairly straightforward language. I'm also biased towards Python, because I think it is the CS gods' gift to programmers.
User avatar
prophile
level5
level5
Posts: 1541
Joined: Fri Feb 18, 2005 4:17 pm
Location: Southampton, UK
Contact:

Postby prophile » Sat Feb 23, 2008 11:37 am

Objective-C is God's gift to programmers but I wouldn't embed it in a game.

In my experience, Lua is a great language for game embedding.
User avatar
Dark Phoenix
level1
level1
Posts: 34
Joined: Wed Jun 23, 2004 12:53 am
Location: Infernal Battlefields of Acheron

Postby Dark Phoenix » Sun Mar 02, 2008 12:55 am

I guess my only remaining concern, then, is how inheritance, interactions, and objects are managed - i.e. if I were to treat all in-game entities as objects/state machines, how would I go about defining interactions between, say, the player and the elevator object Chris is currently working on?
"There is no idea so good it can't be ruined by a few well-placed idiots." - Scott Adams,

creator of "Dilbert"



Sometimes you're the bug, and sometimes you're the windshield.
niq
level0
Posts: 1
Joined: Wed Mar 05, 2008 12:30 am

Postby niq » Wed Mar 05, 2008 12:49 am

I was going to recommend you to talk to the guys at Unknown Worlds, until I saw this: http://www.unknownworlds.com/decoda.

Their opinion is probably going to be fairly biased. Still, they are currently using Lua in Natural Selection 2.
m0pey
level0
Posts: 1
Joined: Wed Mar 05, 2008 2:05 pm

Postby m0pey » Wed Mar 05, 2008 2:08 pm

There's a language that's based on Lua but with in built classes called Squirrel which might be worth a look. It's supposed to be a little bit faster as well. There's not as much documentation around though but you can take techniques from lua and apply them.
Awesome work by the way guys.

Return to “Introversion Blog”

Who is online

Users browsing this forum: No registered users and 4 guests