Thread: Table Sorting
View Single Post
07-17-14, 03:23 PM   #13
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Phanx View Post
As Dridzt said, you can't do that. That's the whole point of the code I posted. You bypass this "problem" by having one table that stores key/value pairs, and a second table that stores a sorted list of the keys from the first table. It's neither possible nor necessary to sort the keys in a table in Lua. The only sorting that's possible is on the values of an indexed table.

If you think that what I posted will not work for what you're trying to do, please explain more clearly what you're trying to do.
I understand that i just wanted to dodge to use the indexed method.

My table looks like this, and i want to reach each table easily, and since the table is gonna be really big i rather not keep more helper tables for it:

Lua Code:
  1. local catz = {
  2.     -- Sorted table
  3.     [...],
  4.     ["Unit: Player"] = {
  5.         -- Sort this like how you add the values
  6.         [...],
  7.         ["PlayerFrame"] = {
  8.             -- Well this is sorted
  9.             [1] = "TopLeft",
  10.             [2] = "UIParent",
  11.             [3] = "TopLeft",
  12.             [4] = 19,
  13.             [5] = -4,
  14.         },
  15.         ["PlayerPVPIcon"] = {
  16.             [1] = "TopLeft",
  17.             [2] = "PlayerFrame",
  18.             [3] = "TopLeft",
  19.             [4] = 18,
  20.             [5] = -20,
  21.         },
  22.         [...],
  23.     },
  24.     ["Unit: Target"] = {
  25.         [...],
  26.         ["TargetFrame"] = {
  27.             [1] = "TopLeft",
  28.             [2] = "UIParent",
  29.             [3] = "TopLeft",
  30.             [4] = 250,
  31.             [5] = -4,
  32.         },
  33.         [...],
  34.     },
  35.     [...],
  36. }

The issue with the indexed method:

Lua Code:
  1. local cats = {
  2.     ["Unit: Player"] = {
  3.         [1] = {name = L["Player"], frame = "PlayerFrame", pos = {[1] = "TopLeft", [2] = "UIParent", [3] = "TopLeft", [4] = 19, [5] = -4,}},
  4.     },
  5. }

How the hell am I gonna reach easily the "pos" table, if i only know the frame's name?

Last edited by Resike : 07-17-14 at 03:31 PM.
  Reply With Quote