"Lua / C# comparison" is Inaccurate in Some Places

The Lua code sample for tables on this page made a small error in how Lua dictionaries work, under the header of Tables > Dictionary Tables:

Sample:

local dictionary = {
	val1 = "this",
	val2 = "is"
}
 
print(dictionary.val1)  -- Outputs 'this'
print(dictionary[val1])  -- Outputs 'this'
 
dictionary.val1 = nil  -- Removes 'val1' from table
table.remove(dictionary, 1)  -- Also removes 'val1' from table
 
dictionary["val3"] = "a dictionary"  -- Overwrites 'val3' or sets new key-value pair
  • This sample should use strings the first time bracket indexing was used.
  • table.remove shouldn’t be used with dictionaries, as it can only be used on arrays.

Fixed:

local dictionary = {
	val1 = "this",
	val2 = "is"
}
 
print(dictionary.val1)  -- Outputs 'this'
print(dictionary["val1"])  -- Outputs 'this'
 
dictionary.val1 = nil  -- Removes 'val1' from table
 
dictionary["val3"] = "a dictionary"  -- Overwrites 'val3' or sets new key-value pair

As a small nitpick, under the header of Conditional Statements > Ternary Operations:

Sample:

 local max = (x>y and x) or y
  • To my knowledge, parantheses don’t have to be used for Lua ternaries.

Fixed:

local max = x>y and x or y

The description above the sample also uses this style , (a and b) or c, which should be changed to a and b or c for continuity. It might also be useful to add that b cannot be nil either, as that counts as a non-truthy value.

7 Likes

Wow I never knew the wiki offered some C# examples. Nice noticing this, the wiki does deffintely have some little miss types or wrong codes here and there but nothing too bad

5 Likes

I fixed the inaccuracies and added relevant links with further explanation on the conditional operator. The changes should be visible soon! Thank you for the corrections :slight_smile:

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.