Thread Tools Display Modes
03/31/14, 12:22 PM   #1
skyraker
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 154
table.unpack usage

Code:
local test = {1,2,3,4}
a,b,c,d = table.unpack(test)
Why doesn't this work?
  Reply With Quote
03/31/14, 01:00 PM   #2
Halja
 
Halja's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 111
table.upack was added in LUA 5.2?
Unpack alone will work to multi-assign variables from an array.

local test = {1,2,3,4}
a,b,c,d = unpack(test)
d( string.format("%d : %d : %d : %d",a,b,c,d ))
  Reply With Quote
03/31/14, 01:31 PM   #3
skyraker
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 154
Guess I didn't realize it wasn't using 5.2. Unpack does work.
  Reply With Quote
03/31/14, 08:21 PM   #4
Karner
 
Karner's Avatar
Join Date: Mar 2014
Posts: 7
GetUnitAvARank(string unitTag)
Returns: integer rank, integer subRank

What about this for example?

a,b = unpack(GetUnitAvARank("player"))?
  Reply With Quote
03/31/14, 08:47 PM   #5
Errc
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 30
Originally Posted by Karner View Post
GetUnitAvARank(string unitTag)
Returns: integer rank, integer subRank

What about this for example?

a,b = unpack(GetUnitAvARank("player"))?
GetUnitAvARank does not return a table, so no need to unpack it.

Can just do this.
a,b = GetUnitAvARank("player")

Or you could create a table that contains the returned values, and then unpack that. But that is wasteful.
a,b = unpack({GetUnitAvARank("player")})

{GetUnitAvARank("player")} creates a table such like { [1] = rank, [2] = subRank }
  Reply With Quote
03/31/14, 08:55 PM   #6
Karner
 
Karner's Avatar
Join Date: Mar 2014
Posts: 7
Originally Posted by Errc View Post
GetUnitAvARank does not return a table, so no need to unpack it.

Can just do this.
a,b = GetUnitAvARank("player")
I get an error with this. "Function expected instead of nil stack straceback". Working on the table now

Fixed the error; had the function spelt wrong

Last edited by Karner : 03/31/14 at 08:57 PM.
  Reply With Quote
03/31/14, 09:00 PM   #7
Errc
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 30
Originally Posted by Karner View Post
I get an error with this. "Function expected instead of nil stack straceback". Working on the table now
Might not be a function still available in-game. Could of been part of the gutting prior to launch.
  Reply With Quote
03/31/14, 09:10 PM   #8
Karner
 
Karner's Avatar
Join Date: Mar 2014
Posts: 7
Originally Posted by Errc View Post
Might not be a function still available in-game. Could of been part of the gutting prior to launch.
Thanks for the help Errc; It's really helped a lot.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » table.unpack usage


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off