Skip to content

Commit 6fea7e8

Browse files
author
fidgetingbits
committed
Some initial lua support and tests
1 parent 1a28517 commit 6fea7e8

25 files changed

+809
-0
lines changed

data/playground/lua/lua.lua

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
2+
-- This is a single-line comment
3+
4+
--[[
5+
This is a multi-line comment.
6+
It spans multiple lines.
7+
--]]
8+
9+
-- Variables
10+
local a = 42
11+
local b, c = "Hello", "World"
12+
13+
-- Data Types
14+
local number = 3.14
15+
local boolean = true
16+
local string = "Lua is awesome!"
17+
local table = {1, 2, 3}
18+
local nilValue = nil
19+
20+
-- Conditional statements
21+
if a > 10 then
22+
print("a is greater than 10")
23+
elseif a < 10 then
24+
print("a is less than 10")
25+
else
26+
print("a is equal to 10")
27+
end
28+
29+
-- Loops
30+
for i = 1, 5 do
31+
print(i)
32+
end
33+
34+
while b == "Hello" do
35+
print("Still saying hello!")
36+
break
37+
end
38+
39+
-- Functions
40+
function add(x, b)
41+
return x + y
42+
end
43+
44+
local sum = add(5, 7)
45+
print("Sum:", sum)
46+
47+
-- Tables
48+
local person = {
49+
name = "John",
50+
age = 30,
51+
hobbies = {"reading", "gaming", "programming"},
52+
address = {
53+
street = "123 Main St",
54+
city = "Example City"
55+
}
56+
}
57+
58+
-- String manipulation
59+
local concatString = "Hello " .. "World"
60+
61+
-- Metatables and metatable operations
62+
local mt = {
63+
__add = function(a, b) return a + b end,
64+
__sub = function(a, b) return a - b end
65+
}
66+
67+
setmetatable(a, mt)
68+
69+
-- Closures
70+
function makeCounter()
71+
local count = 0
72+
return function()
73+
count = count + 1
74+
return count
75+
end
76+
end
77+
78+
local counter = makeCounter()
79+
80+
-- Coroutines
81+
local co = coroutine.create(function()
82+
for i = 1, 3 do
83+
print("Coroutine", i)
84+
coroutine.yield()
85+
end
86+
end)
87+
88+
-- Error handling
89+
local success, result = pcall(function()
90+
error("This is an error")
91+
end)
92+
93+
if not success then
94+
print("Error:", result)
95+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change arg
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: argumentOrParameter}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
function add(x, b)
16+
return x + y
17+
end
18+
selections:
19+
- anchor: {line: 0, character: 13}
20+
active: {line: 0, character: 13}
21+
marks: {}
22+
finalState:
23+
documentContents: |-
24+
function add(, b)
25+
return x + y
26+
end
27+
selections:
28+
- anchor: {line: 0, character: 13}
29+
active: {line: 0, character: 13}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change arg
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: argumentOrParameter}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
local sum = add(5, 7)
16+
selections:
17+
- anchor: {line: 0, character: 16}
18+
active: {line: 0, character: 16}
19+
marks: {}
20+
finalState:
21+
documentContents: |
22+
local sum = add(, 7)
23+
selections:
24+
- anchor: {line: 0, character: 16}
25+
active: {line: 0, character: 16}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change branch
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: branch}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
if a > 10 then
16+
print("a is greater than 10")
17+
elseif a < 10 then
18+
print("a is less than 10")
19+
else
20+
print("a is equal to 10")
21+
end
22+
selections:
23+
- anchor: {line: 2, character: 4}
24+
active: {line: 2, character: 4}
25+
marks: {}
26+
finalState:
27+
documentContents: |-
28+
if a > 10 then
29+
print("a is greater than 10")
30+
31+
else
32+
print("a is equal to 10")
33+
end
34+
selections:
35+
- anchor: {line: 2, character: 0}
36+
active: {line: 2, character: 0}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change branch
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: branch}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
if a > 10 then
16+
print("a is greater than 10")
17+
elseif a < 10 then
18+
print("a is less than 10")
19+
else
20+
print("a is equal to 10")
21+
end
22+
selections:
23+
- anchor: {line: 5, character: 4}
24+
active: {line: 5, character: 4}
25+
marks: {}
26+
finalState:
27+
documentContents: |-
28+
if a > 10 then
29+
print("a is greater than 10")
30+
elseif a < 10 then
31+
print("a is less than 10")
32+
33+
end
34+
selections:
35+
- anchor: {line: 4, character: 0}
36+
active: {line: 4, character: 0}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change branch
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: branch}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
if a > 10 then
16+
print("a is greater than 10")
17+
elseif a < 10 then
18+
print("a is less than 10")
19+
else
20+
print("a is equal to 10")
21+
end
22+
selections:
23+
- anchor: {line: 1, character: 4}
24+
active: {line: 1, character: 4}
25+
marks: {}
26+
finalState:
27+
documentContents: |-
28+
29+
elseif a < 10 then
30+
print("a is less than 10")
31+
else
32+
print("a is equal to 10")
33+
end
34+
selections:
35+
- anchor: {line: 0, character: 0}
36+
active: {line: 0, character: 0}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change call
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: functionCall}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
print("a is greater than 10")
16+
selections:
17+
- anchor: {line: 0, character: 0}
18+
active: {line: 0, character: 0}
19+
marks: {}
20+
finalState:
21+
documentContents: |+
22+
23+
selections:
24+
- anchor: {line: 0, character: 0}
25+
active: {line: 0, character: 0}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change callee
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: functionCallee}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
print("a is greater than 10")
16+
selections:
17+
- anchor: {line: 0, character: 0}
18+
active: {line: 0, character: 0}
19+
marks: {}
20+
finalState:
21+
documentContents: |
22+
("a is greater than 10")
23+
selections:
24+
- anchor: {line: 0, character: 0}
25+
active: {line: 0, character: 0}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change comment
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: comment}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
-- This is a single-line comment
16+
selections:
17+
- anchor: {line: 0, character: 0}
18+
active: {line: 0, character: 0}
19+
marks: {}
20+
finalState:
21+
documentContents: |+
22+
23+
selections:
24+
- anchor: {line: 0, character: 0}
25+
active: {line: 0, character: 0}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change comment
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: comment}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
--[[
16+
This is a multi-line comment.
17+
It spans multiple lines.
18+
--]]
19+
selections:
20+
- anchor: {line: 2, character: 4}
21+
active: {line: 2, character: 4}
22+
marks: {}
23+
finalState:
24+
documentContents: ""
25+
selections:
26+
- anchor: {line: 0, character: 0}
27+
active: {line: 0, character: 0}

0 commit comments

Comments
 (0)