Skip to content

Commit d5b0881

Browse files
authored
Update examples to match styling (#973)
## Changes Updated names to match official Roblox Lua Styling guide for consistency. Apologies for the multiple commits due to web editor. https://roblox.github.io/lua-style-guide/#naming ## Checks By submitting your pull request for review, you agree to the following: - [x] This contribution was created in whole or in part by me, and I have the right to submit it under the terms of this repository's open source licenses. - [x] I understand and agree that this contribution and a record of it are public, maintained indefinitely, and may be redistributed under the terms of this repository's open source licenses. - [x] To the best of my knowledge, all proposed changes are accurate. ---------
1 parent f745292 commit d5b0881

File tree

3 files changed

+50
-50
lines changed

3 files changed

+50
-50
lines changed

content/en-us/luau/queues.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,20 @@ function Queue.new<T>(): Queue<T>
5858
end
5959

6060
-- Check if the queue is empty
61-
function Queue.IsEmpty<T>(self: Queue<T>)
61+
function Queue.isEmpty<T>(self: Queue<T>)
6262
return self._first > self._last
6363
end
6464

6565
-- Add a value to the queue
66-
function Queue.Enqueue<T>(self: Queue<T>, value: T)
66+
function Queue.enqueue<T>(self: Queue<T>, value: T)
6767
local last = self._last + 1
6868
self._last = last
6969
self._queue[last] = value
7070
end
7171

7272
-- Remove a value from the queue
73-
function Queue.Dequeue<T>(self: Queue<T>): T
74-
if self:IsEmpty() then
73+
function Queue.dequeue<T>(self: Queue<T>): T
74+
if self:isEmpty() then
7575
error("Cannot dequeue from empty queue")
7676
end
7777

@@ -96,27 +96,27 @@ local Queue = require(ReplicatedStorage:WaitForChild("Queue"))
9696
local myQueue = Queue.new()
9797

9898
-- Add some values to the queue
99-
myQueue:Enqueue(5)
100-
myQueue:Enqueue(10)
101-
myQueue:Enqueue(15)
99+
myQueue:enqueue(5)
100+
myQueue:enqueue(10)
101+
myQueue:enqueue(15)
102102

103103
-- myQueue = { 5, 10, 15 }
104104

105105
-- Remove one value from the queue
106-
local first = myQueue:Dequeue()
106+
local first = myQueue:dequeue()
107107
print("The first value added to the queue was", first)
108108

109109
-- myQueue = { 10, 15 }
110110

111111
-- Add more values to the queue
112-
myQueue:Enqueue(20)
113-
myQueue:Enqueue(25)
114-
myQueue:Enqueue(30)
112+
myQueue:enqueue(20)
113+
myQueue:enqueue(25)
114+
myQueue:enqueue(30)
115115

116116
-- myQueue = { 10, 15, 20, 25, 30 }
117117

118118
-- Remove another value from the queue
119-
local second = myQueue:Dequeue()
119+
local second = myQueue:dequeue()
120120
print("The second value added to the queue was", second)
121121

122122
-- myQueue = { 15, 20, 25, 30 }

content/en-us/luau/stacks.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ function Stack.new()
2626
end
2727

2828
-- Check if the stack is empty
29-
function Stack:IsEmpty()
29+
function Stack:isEmpty()
3030
return #self._stack == 0
3131
end
3232

3333
-- Put a new value onto the stack
34-
function Stack:Push(value)
34+
function Stack:push(value)
3535
table.insert(self._stack, value)
3636
end
3737

3838
-- Take a value off the stack
39-
function Stack:Pop()
40-
if self:IsEmpty() then
39+
function Stack:pop()
40+
if self:isEmpty() then
4141
return nil
4242
end
4343

@@ -57,21 +57,21 @@ local s = Stack.new()
5757

5858
-- Change the stack Resulting stack Output
5959

60-
s:Push(1) -- {1}
60+
s:push(1) -- {1}
6161

62-
s:Push(5) -- {1, 5}
62+
s:push(5) -- {1, 5}
6363

64-
s:Push(10) -- {1, 5, 10}
64+
s:push(10) -- {1, 5, 10}
6565

66-
print(s:Pop()) -- {1, 5} 10
66+
print(s:pop()) -- {1, 5} 10
6767

68-
print(s:Pop()) -- {1} 5
68+
print(s:pop()) -- {1} 5
6969

70-
s:Push(20) -- {1, 20}
70+
s:push(20) -- {1, 20}
7171

72-
print(s:Pop()) -- {1} 20
72+
print(s:pop()) -- {1} 20
7373

74-
print(s:Pop()) -- {} 1
74+
print(s:pop()) -- {} 1
7575
```
7676

7777
<Alert severity="warning">

content/en-us/luau/tables.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ To create a dictionary table, define each **key** followed by `=` and the **valu
141141

142142
```lua
143143
local testDictionary = {
144-
FruitName = "Lemon",
145-
FruitColor = "Yellow",
146-
Sour = true
144+
fruitName = "Lemon",
145+
fruitColor = "Yellow",
146+
sour = true
147147
}
148148
```
149149

@@ -153,7 +153,7 @@ The keys for dictionaries can be numbers, strings, and objects. For example, a k
153153
local part = Instance.new("Part")
154154

155155
local testDictionary = {
156-
PartType = "Block",
156+
partType = "Block",
157157
[part] = true
158158
}
159159
```
@@ -166,11 +166,11 @@ To read from a dictionary, add a pair of brackets after its reference and specif
166166
local part = Instance.new("Part")
167167

168168
local testDictionary = {
169-
PartType = "Block",
169+
partType = "Block",
170170
[part] = true
171171
}
172172
-- Include quotes for string keys
173-
print(testDictionary["PartType"]) -- Block
173+
print(testDictionary["partType"]) -- Block
174174
-- Omit quotes for non-string keys
175175
print(testDictionary[part]) -- true
176176
```
@@ -181,20 +181,20 @@ To define or rewrite the value of a new or existing dictionary key, declare the
181181

182182
```lua
183183
local testDictionary = {
184-
FruitName = "Lemon",
185-
Sour = true
184+
fruitName = "Lemon",
185+
sour = true
186186
}
187187

188188
-- Change value of existing keys
189-
testDictionary["FruitName"] = "Cherry"
190-
testDictionary["Sour"] = false
189+
testDictionary["fruitName"] = "Cherry"
190+
testDictionary["sour"] = false
191191

192192
-- Insert new key-value pair
193-
testDictionary["FruitCount"] = 10
193+
testDictionary["fruitCount"] = 10
194194

195-
print(testDictionary["FruitName"]) -- Cherry
196-
print(testDictionary["Sour"]) -- false
197-
print(testDictionary["FruitCount"]) -- 10
195+
print(testDictionary["fruitName"]) -- Cherry
196+
print(testDictionary["sour"]) -- false
197+
print(testDictionary["fruitCount"]) -- 10
198198
```
199199

200200
### Iterating over Dictionaries
@@ -203,19 +203,19 @@ To iterate over a dictionary, use the global `pairs()` function in a `for` loop:
203203

204204
```lua
205205
local testDictionary = {
206-
FruitName = "Lemon",
207-
FruitColor = "Yellow",
208-
Sour = true
206+
fruitName = "Lemon",
207+
fruitColor = "Yellow",
208+
sour = true
209209
}
210210

211211
for key, value in pairs(testDictionary) do
212212
print(key, value)
213213
end
214214

215215
--[[ Resulting output:
216-
FruitName Lemon
217-
Sour true
218-
FruitColor Yellow
216+
fruitName Lemon
217+
sour true
218+
fruitColor Yellow
219219
]]
220220
```
221221

@@ -229,19 +229,19 @@ To remove or erase a key-value pair from a dictionary, set its value for a key t
229229

230230
```lua
231231
local testDictionary = {
232-
FruitName = "Lemon",
233-
FruitColor = "Yellow",
234-
Sour = true
232+
fruitName = "Lemon",
233+
fruitColor = "Yellow",
234+
sour = true
235235
}
236236

237-
testDictionary["Sour"] = nil
237+
testDictionary["sour"] = nil
238238

239239
for key, value in pairs(testDictionary) do
240240
print(key, value)
241241
end
242242
--[[ Resulting output:
243-
FruitName Lemon
244-
FruitColor Yellow
243+
fruitName Lemon
244+
fruitColor Yellow
245245
]]
246246
```
247247

0 commit comments

Comments
 (0)