Tables बनाना
एक table एक container है जो keys के नीचे values store करता है, और यह एकमात्र data structure है जो Lua के पास है।
In this page:
Tables बनाना
Tables curly braces से बनाई जाती हैं और nil को छोड़कर किसी भी value को key की तरह hold कर सकती हैं। same table positional items और named fields mix कर सकता है। Tables objects हैं, इसलिए एक table को दूसरे variable में assign करना इसे copy करने की बजाय share करता है।
Note:
क्योंकि tables Lua का एकमात्र structure हैं, arrays, records, sets, और modules सब बस tables हैं।
उदाहरण: Creating tables
local t = {10, 20, name = "box", [3.5] = "float key"}
print(t[1], t[2], t.name, t[3.5])
print(t.missing)
local alias = t
alias.name = "renamed"
print(t.name)
print(type(t), #{})
-- Output:
-- 10 20 box float key
-- nil
-- renamed
-- table 0
Login to try C/C++/Java/PHP code in the editor
आम गलतियां
- यह उम्मीद करना कि assign होने पर एक table variable एक copy hold करेगा
- nil को एक key की तरह इस्तेमाल करना
- constructor {} को एक block से confuse करना
चैप्टर सारांश
- Tables {} से बनती हैं
- nil को छोड़कर कोई भी value एक key हो सकती है
- एक table arrays और fields mix कर सकता है
- Assignment reference copy करता है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: