github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/runtime/lua/godepth.lua (about)

     1  -- Tests for measures agains irrecoverable stack overflows
     2  
     3  -- Recursive table.sort
     4  do
     5      local n = 0
     6      local x = {}
     7      setmetatable(x, {__lt=function(x, y)
     8          n = n + 1
     9          table.sort{x, y}
    10      end})
    11      print(pcall(table.sort, {x, x}))
    12      --> ~false\t.*stack overflow
    13      print(n <= 1000 and n >= 900)
    14      --> =true
    15  end
    16  
    17  -- Recursive string.gsub
    18  do
    19      local n = 0
    20      local function f()
    21          n = n + 1
    22          string.gsub("x", ".", f)
    23      end
    24      print(pcall(f))
    25      --> ~false\t.*stack overflow
    26      print(n <= 1000 and n >= 900)
    27      --> =true
    28  end