diff --git a/lua-style.md b/lua-style.md index 78b02fc..be74886 100644 --- a/lua-style.md +++ b/lua-style.md @@ -9,6 +9,8 @@ 2. Or neither of them 3. Put spaces *after* the separator (if at all), never before +Examples: + local outer = { {"inner",1}, {"inner",2}, } @@ -16,6 +18,8 @@ 2. Or don't put any items on the same line as the curly braces. 3. Indent the items of the table +Examples: + local oneline = {'hello', 'world',} lcoal multiline = { 'hello', @@ -28,6 +32,8 @@ 1. Use commas (`,`) to separate order-dependant items (list) 2. Use semicolons (`;`) to separate order-independant items (set) +Examples: + local ingredients = { "eggs"; "flour"; "milk"; } local steps = { "mix", "fry", } @@ -37,6 +43,8 @@ 3. Put no separator after the last element if external conditions must change for an additional item to be inserted. +Examples: + local color = { 0xff, 0x20, 0x40 } local line = { {0, 0}, {0, 20}, {20, 20}, } @@ -48,6 +56,8 @@ open-ended sequences 3. Or use a different separator to signal that no items should be added +Examples: + local pancakes = { 'mix', 'fry'; ingredients = { 'milk'; 'eggs'; 'flour' }; @@ -68,6 +78,8 @@ 2. Use semicolons otherwise 3. Apply same rules as with sequnces for separator after last element +Examples: + local point = {x=20, y=30} local tasks = { monday = {'call steve'}, tuesday = {'fix kitchen door'}, } local person = { name="John Doe"; age="Unknown" } @@ -77,5 +89,7 @@ 2. Use square brackets for numbers acting as keys in a map 3. Judge based on semantic meaning, not on technicalities +Examples: + local ages = { [20]="John, Henry"; [21]="William"; } local errors = { [1]="File not Found"; [2]="Permission Denied" }