View Single Post
10-20-15, 10:20 AM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
This will probably work better.

Lua Code:
  1. local function FillTableStructure(tbl,...)
  2. --  Check if sent a table and cache for return
  3.     tbl=tbl or {};
  4.     local ret=tbl;
  5.  
  6.     for i=1,select("#",...) do
  7.         local idx=select(i,...);--  Index from argument list
  8.         local entry=tbl[idx];--     Cache current entry if any
  9.  
  10. --      Make table and link to index if not exist
  11.         if not entry then
  12.             entry={};
  13.             tbl[idx]=entry;
  14.         end
  15.  
  16.         tbl=entry;--    Select entry as current table
  17.     end
  18.  
  19.     return ret;
  20. end
  21.  
  22. --  If the table was a local, you can run the function like this
  23. ADVANCED_INTERFACE_GLOBAL_CONSTANTS=FillTableStructure(ADVANCED_INTERFACE_GLOBAL_CONSTANTS,"STAMPS","ADVANCED_USER_INTERFACE");
  24.  
  25. --  If the table was a global, you technically could give it _G as the base table or use the same line above
  26. FillTableStructure(_G,"ADVANCED_INTERFACE_GLOBAL_CONSTANTS","STAMPS","ADVANCED_USER_INTERFACE");

Unlike Barjack's function, this keeps existing entries and allows numeric and object keys. It's still much less efficient than Torhal's code.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 10-20-15 at 10:32 AM.
  Reply With Quote