WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Why does tinsert work and table.insert not (https://www.wowinterface.com/forums/showthread.php?t=57667)

Yukyuk 11-10-19 01:53 AM

Why does tinsert work and table.insert not
 
I have the following piece of code:

Lua Code:
  1. -------------------------------------------------------------------------------
  2. --  Fill the right side scroll table
  3. -------------------------------------------------------------------------------
  4. local function CA_Fill_CAR_Table(counter)
  5.     if CAL_Scroll_Table[CAL_idx - (6 - counter)].Reference ~= "" then
  6.         --print(CAL_Scroll_Table[CAL_idx - (6 - counter)].Reference)
  7.         local reference = CAL_Scroll_Table[CAL_idx - (6 - counter)].Reference
  8.         local table = CA_Db[reference]
  9.  
  10.         CAR_row_count = 0
  11.         CAR_Scroll_Table = {}
  12.        
  13.         for i = 1, #table do
  14.             CAR_Table = {}
  15.             CAR_row_count = CAR_row_count + 1
  16.             CAR_Table.Name      = table[i][1]
  17.             CAR_Table.Status    = table[i][2]
  18.             tinsert(CAR_Scroll_Table,CAR_Table)    
  19.         end    
  20.     end
  21.    
  22.     CA_TABS_RS.scrollFrame.ScrollBar:SetValue(0)   
  23.     CA_TABS_RS_ScrollFrameUpdate()
  24. end

And it is working as intended.
But I would like to know why it works when I use tinsert and why it won't work when I use table.insert.

When I use table.insert I get the following error.

Lua Code:
  1. 1x ClassicAchievements\CA_Tabs.lua:69: attempt to call field 'insert' (a nil value)
  2. ClassicAchievements\CA_Tabs.lua:69: in function <ClassicAchievements\CA_Tabs.lua:55>
  3. ClassicAchievements\CA_Tabs.lua:208: in function <ClassicAchievements\CA_Tabs.lua:207>
  4.  
  5. Locals:
  6. counter = 3
  7. reference = "LOVE"
  8. table = <table> {
  9.  1 = <table> {
  10.  }
  11.  2 = <table> {
  12.  }
  13.  3 = <table> {
  14.  }
  15.  4 = <table> {
  16.  }
  17.  5 = <table> {
  18.  }
  19.  6 = <table> {
  20.  }
  21.  7 = <table> {
  22.  }
  23.  8 = <table> {
  24.  }
  25.  9 = <table> {
  26.  }
  27.  10 = <table> {
  28.  }
  29.  11 = <table> {
  30.  }
  31.  12 = <table> {
  32.  }
  33.  13 = <table> {
  34.  }
  35.  14 = <table> {
  36.  }
  37.  15 = <table> {
  38.  }
  39.  16 = <table> {
  40.  }
  41.  17 = <table> {
  42.  }
  43.  18 = <table> {
  44.  }
  45.  19 = <table> {
  46.  }
  47.  20 = <table> {
  48.  }
  49.  21 = <table> {
  50.  }
  51. }
  52. (for index) = 1
  53. (for limit) = 21
  54. (for step) = 1
  55. i = 1
  56. (*temporary) = nil
  57. (*temporary) = <table> {
  58. }
  59. (*temporary) = <table> {
  60.  Name = "Adder"
  61.  Status = true
  62. }
  63. (*temporary) = "attempt to call field 'insert' (a nil value)"
  64. CAL_Scroll_Table = <table> {
  65.  1 = <table> {
  66.  }
  67.  2 = <table> {
  68.  }
  69.  3 = <table> {
  70.  }
  71. }
  72. CAL_idx = 6
  73. CAR_row_count = 1
  74. CAR_Scroll_Table = <table> {
  75. }
  76. CAR_Table = <table> {
  77.  Name = "Adder"
  78.  Status = true
  79. }

Ailae 11-10-19 03:04 AM

You're defining a variable table at row 8 in your code, overwriting the default table implementation.

Lua Code:
  1. table.insert({},1) -- works
  2. table = {}
  3. table.insert({},1) -- nil error

Yukyuk 11-10-19 04:54 AM

Quote:

Originally Posted by Ailae (Post 334525)
You're defining a variable table at row 8 in your code, overwriting the default table implementation.

Lua Code:
  1. table.insert({},1) -- works
  2. table = {}
  3. table.insert({},1) -- nil error

Of course :rolleyes:

Thank you Ailae :)


All times are GMT -6. The time now is 06:11 AM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI