lua version

How To's, Questions, and Solutions for problems. This covers anything from computer hardware problems to software recommendations to tutorials for various software programs.

Note: Neither Gametoast nor any of its members/visitors are responsible for any damage to your computer as a result from advice given in this forum. Follow advice at your own risk and be sure to back up any important files.

Moderator: Moderators

Post Reply
Sporadia
Corporal
Corporal
Posts: 151
Joined: Thu Jan 24, 2019 11:02 pm
Projects :: No Mod project currently
Games I'm Playing :: None
xbox live or psn: No gamertag set

lua version

Post by Sporadia »

This isn't a question, it's just a very niche technical note that I though worth making (and this probably isn't news to seasoned modders).

The SWBF2 lua interpreter runs lua version 5.0.2.

There's an easy way to check this, because all lua interpreters store the lua version in a global variable called _VERSION so you can just throw this print command in a mission lua, and it will print the lua version to the debug log:

Code: Select all

print("The SWBF2 lua interpreter uses:", _VERSION)
A word to the wise (ie anyone who goes looking for lua guides, either online or in books), there are some notable differences between lua 5.0, lua 5.1, lua 5.2 and so on. For example, if you want to find the length of a table in lua 5.0 you would do this:

Code: Select all

local example = {1, 2, 4}
local length = table.getn(example)
But in lua 5.1 and beyond, you would do this:

Code: Select all

local example = {1, 2, 4}
local length = #example
^ This does not work in SWBF2, because this # syntax wasn't added until lua 5.1 (and table.getn was removed in lua 5.2). That might be the best example because if anyone is trying to figure out how to do something and they go looking on stack exchange, or in a textbook etc, they'll notice # is used very liberally now. (Not that I know much about lua, but I don't recommend swapping #t with table.getn(t) for everything it's used for now. There's probably a tidier way to write the code in lua 5.0). Supposedly lua 5.2 came with some fairly significant changes too but I'm not familiar enough with lua to say what they are. The addition of a goto statement was one; you can't use that in SWBF2.

So that's just something to keep in the back of your mind. A final note is that lua.org have their own textbook on lua called Programming in Lua. They host the first edition of that book for free online, and by fortunate coincidence, the first edition specifically is the edition released for lua 5.0. (It's less good news if you want a printed copy, because the first edition is the hardest to find). But I've found the online version at least to be a good resource for modding SWBF2.
MileHighGuy
Jedi
Jedi
Posts: 1194
Joined: Fri Dec 19, 2008 7:58 pm

Re: lua version

Post by MileHighGuy »

I thought it was 5.0.4. nice find!

Also the modulus operator % is math.mod in Lua 5.0
Post Reply