Skip to content

Commit

Permalink
fix rune in lua
Browse files Browse the repository at this point in the history
  • Loading branch information
CMA2401PT committed Jul 31, 2024
1 parent 45680d7 commit 809cdc5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions stringlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ func strGmatch(L *LState) int {

func strLen(L *LState) int {
str := L.CheckString(1)
L.Push(LNumber(len(str)))
len := len([]rune(str))
L.Push(LNumber(len))
return 1
}

Expand Down Expand Up @@ -415,11 +416,11 @@ func strSub(L *LState) int {
str := L.CheckString(1)
start := luaIndex2StringIndex(str, L.CheckInt(2), true)
end := luaIndex2StringIndex(str, L.OptInt(3, -1), false)
l := len(str)
l := len([]rune(str))
if start >= l || end < start {
L.Push(emptyLString)
} else {
L.Push(LString(str[start:end]))
L.Push(LString(([]rune(str))[start:end]))
}
return 1
}
Expand All @@ -434,7 +435,7 @@ func luaIndex2StringIndex(str string, i int, start bool) int {
if start && i != 0 {
i -= 1
}
l := len(str)
l := len([]rune(str))
if i < 0 {
i = l + i + 1
}
Expand Down

0 comments on commit 809cdc5

Please sign in to comment.