Poster: Slouken at 2006-08-30 15:53:09 Subject: Lua 5.1 |
| | WoW will be using Lua 5.1 for the expansion.
For the most part, this is a seamless transition, but there is one syntax change that will need to be made in a lot of addons:
for k,v in table do stuff end
changes to:
for k,v in pairs(table) do stuff end
Also, the main advantage of Lua 5.1 is the incremental garbage collection, and the full functionality of the 5.1 collectgarbage() function is available to the WoW scripting system.
|
| | http://forums.worldofwarcraft.com/thread.html?topicId=14682657&pageNo=1&sid=1#0 |
Poster: Slouken at 2006-08-31 10:25:03 Subject: Re: Lua 5.1 |
| | You can use the new "pairs(table)" semantic now, by the way. :)
|
| | http://forums.worldofwarcraft.com/thread.html?topicId=14682657&pageNo=2&sid=1#28 |
Poster: Slouken at 2006-08-31 15:03:56 Subject: Re: Lua 5.1 |
| | WoW Lua 5.1 is currently compiled with these options:
#define LUAI_GCPAUSE 200
#define LUAI_GCMUL 200
#undef LUA_COMPAT_GETN
#undef LUA_COMPAT_VARARG
#undef LUA_COMPAT_MOD
#undef LUA_COMPAT_LSTR
#undef LUA_COMPAT_GFIND
There are also these changes:
Added difftime()
Added gmatch() as an alias for str.gmatch()
Added strmatch as an alias for str.match()
Added strrev() as an alias for str.reverse()
The alias mod() now maps to math.fmod()
|
| | http://forums.worldofwarcraft.com/thread.html?topicId=14682657&pageNo=2&sid=1#38 |
Poster: Slouken at 2006-08-31 15:18:10 Subject: Re: Lua 5.1 |
| | This construct:
function foo(...) for i in arg.n do local v = arg[i] end end
should be changed to:
function foo(...) for i in select("#", ...) do local v = select(i, ...) end end
|
| | http://forums.worldofwarcraft.com/thread.html?topicId=14682657&pageNo=3&sid=1#41 |
Poster: Slouken at 2006-08-31 15:18:10 Subject: Re: Lua 5.1 |
| | This construct:
function foo(...) for i in arg.n do local v = arg[i] end end
should be changed to:
function foo(...) for i in select("#", ...) do local v = (select(i, ...)) end end
[ Post edited by Slouken ]
|
| | http://forums.worldofwarcraft.com/thread.html?topicId=14682657&pageNo=3&sid=1#41 |
Poster: Slouken at 2006-08-31 15:18:10 Subject: Re: Lua 5.1 |
| | This construct:
function foo(...) for i in arg.n do local v = arg[i] end end
should be changed to:
function foo(...) for i in select("#", ...) do local v = select(i, ...) end end
[ Post edited by Slouken ]
|
| | http://forums.worldofwarcraft.com/thread.html?topicId=14682657&pageNo=3&sid=1#41 |
Poster: Slouken at 2006-08-31 15:18:10 Subject: Re: Lua 5.1 |
| | This construct:
function foo(...) for i=1, arg.n do local v = arg[i] end end
should be changed to:
function foo(...) for i=1, select("#", ...) do local v = select(i, ...) end end
[ Post edited by Slouken ]
|
| | http://forums.worldofwarcraft.com/thread.html?topicId=14682657&pageNo=3&sid=1#41 |
Poster: Slouken at 2006-08-31 18:47:55 Subject: Re: Lua 5.1 |
| | *laugh* Okay, between the three of us, I think we got it right.
|
| | http://forums.worldofwarcraft.com/thread.html?topicId=14682657&pageNo=3&sid=1#52 |
Poster: Slouken at 2006-09-01 23:50:07 Subject: Re: Lua 5.1 |
| |
Q u o t e:
There is also a subtlety in the way that the new "select" function works, that is a bit obscure in the documentation.
function f (...)
print (select (2, ...))
end -- f
f (22, 33, 44) --> 33 44
Note the output of both 33 and 44, as the select function returns from the nominated argument onwards. The examples given earlier obscure this point a bit because they are assigning to a single variable, eg.
local v = select(i, ...) --> assigns to v, discards extra results
[/ul]
This is actually a neat trick, and allows you to do things like:
function foo(a, ...)
for i=1, select(#, ...), 3 do
local r, g, b = select(i, ...);
something colorful
end
end
|
| | http://forums.worldofwarcraft.com/thread.html?topicId=14682657&pageNo=4&sid=1#67 |
Poster: Slouken at 2006-09-03 07:27:46 Subject: Re: Lua 5.1 |
| | FYI, the game already does garbage collection when zoning. :)
|
| | http://forums.worldofwarcraft.com/thread.html?topicId=14682657&pageNo=4&sid=1#72 |
Poster: Slouken at 2006-08-30 14:53:09 Subject: Lua 5.1 |
| | 0">
|