Commit affd4e4
committed
fix: stack overflow in table.concat function
The previous implementation of tableConcat was pushing all values and
separators onto the Lua stack before concatenating them, which caused
stack overflow with large tables.
This fix changes the implementation to build the result string
incrementally rather than pushing all values onto the stack first,
preventing stack overflow with large tables.
Example that would previously fail but now works correctly:
```
package main
import "github.com/yuin/gopher-lua"
func main() {
var L *lua.LState
var err error
L = lua.NewState()
defer L.Close()
err = L.DoString(`
local t = {}
for i = 1, 10000 do
t[i] = tostring(i)
end
local s = table.concat(t, ',')
`)
if err != nil {
println(err.Error())
}
}
```1 parent ccacf66 commit affd4e4
1 file changed
Lines changed: 4 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | | - | |
| 69 | + | |
71 | 70 | | |
72 | 71 | | |
73 | 72 | | |
74 | 73 | | |
75 | 74 | | |
76 | | - | |
| 75 | + | |
77 | 76 | | |
78 | | - | |
| 77 | + | |
79 | 78 | | |
80 | 79 | | |
81 | | - | |
| 80 | + | |
82 | 81 | | |
83 | 82 | | |
84 | 83 | | |
| |||
0 commit comments