github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/lib/golib/lua/disablegolib.quotas.lua (about)

     1  local function checkflag(flag, f, ...)
     2      if f then
     3          local st, err = pcall(f, ...)
     4          if st or not string.match(err, flag, 1, true) then
     5              print(flag, "not found:", err)
     6              return
     7          end
     8      end
     9      print("ok")
    10  end
    11  
    12  -- golib not cpu safe
    13  runtime.callcontext({kill={cpu=10000}}, function()
    14      local ctx = runtime.context()
    15  
    16      checkflag("cpusafe", double, 2)
    17      --> =ok
    18  
    19      checkflag("cpusafe", function() return polly.Age end)
    20      --> =ok
    21  
    22      checkflag("cpusafe", golib.import, "fmt")
    23      --> =ok
    24  end)
    25  
    26  -- golib not memory safe
    27  runtime.callcontext({kill={memory=10000}}, function()
    28      local ctx = runtime.context()
    29  
    30      checkflag("memsafe", double, 2)
    31      --> =ok
    32  
    33      checkflag("memsafe", function() return polly.Age end)
    34      --> =ok
    35  
    36      checkflag("memsafe", golib.import, "fmt")
    37      --> =ok
    38  end)
    39  
    40  -- golib not io safe
    41  runtime.callcontext({flags="iosafe"}, function()
    42      local ctx = runtime.context()
    43  
    44      checkflag("iosafe", double, 2)
    45      --> =ok
    46  
    47      checkflag("iosafe", function() return polly.Age end)
    48      --> =ok
    49  
    50      checkflag("iosafe", golib.import, "fmt")
    51      --> =ok
    52  end)