-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_modern.lua
More file actions
69 lines (58 loc) · 1.47 KB
/
Copy pathtest_modern.lua
File metadata and controls
69 lines (58 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
-- Test modern Lua 5.4+ syntax features
-- 1. Integer division operator
print("Integer division:", 10 // 3)
-- 2. Bitwise operators
local a = 10 -- Decimal instead of binary
local b = 15 -- Decimal instead of hex
print("Bitwise AND:", a & b)
print("Bitwise OR:", a | b)
print("Bitwise XOR:", a ~ b)
print("Left shift:", a << 2)
print("Right shift:", a >> 1)
-- 3. New string literals with \z
local longString = "This is a long string \z
that spans multiple \z
lines without newlines"
print(longString)
-- 4. Closures with proper syntax
local function createCounter()
local count = 0
return function()
count = count + 1 -- Standard assignment
return count
end
end
local counter = createCounter()
print("Counter:", counter())
print("Counter:", counter())
-- 5. Table constructors with new syntax
local tbl = {
[1] = "first",
[2] = "second",
["key"] = "value"
}
-- 6. Local functions
local function fastFunc()
-- This is a regular function
local file = io.open("test.txt", "w")
return file
end
-- 7. Pattern matching with new features
local str = "Hello123World"
local num = str:match("%d+")
print("Matched number:", num)
-- 8. Constants (as regular variables)
local PI = 3.14159
print("PI:", PI)
-- 9. Type annotations (conceptual)
---@type string
local name = "Test"
-- 10. Advanced table operations
local nested = {
level1 = {
level2 = {
value = 42
}
}
}
print("Nested value:", nested.level1.level2.value)