github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/lib/base/lua/load.quotas.lua (about) 1 -- load tests 2 do 3 -- If passed a function load consumes cpu and memory to build the string 4 5 print(runtime.callcontext({kill={memory=10000}}, load, function() return "print('hello')\n" end)) 6 --> =killed 7 8 print(runtime.callcontext({kill={cpu=10000}}, load, function() return "print('hello')\n" end)) 9 --> =killed 10 11 -- Same if passed a big string 12 13 print(runtime.callcontext({kill={memory=10000}}, load, ("print('hello')"):rep(1000, "\n"))) 14 --> =killed 15 16 print(runtime.callcontext({kill={cpu=10000}}, load, ("print('hello')"):rep(10000, "\n"))) 17 --> =killed 18 end 19 20 -- loadfile tests 21 do 22 -- loadfile consumes cpu and memory to load the string 23 24 local ctx, m = runtime.callcontext({kill={memory=100000}}, loadfile, "lua/big.lua.notest") 25 print(ctx, m()) 26 --> =done hello 27 28 print(runtime.callcontext({kill={memory=10000}}, loadfile, "lua/big.lua.notest")) 29 --> =killed 30 31 local ctx, m = runtime.callcontext({kill={cpu=10000}}, loadfile, "lua/big.lua.notest") 32 print(ctx, m()) 33 --> =done hello 34 35 print(runtime.callcontext({kill={cpu=1000}}, loadfile, "lua/big.lua.notest")) 36 --> =killed 37 end 38 39 -- dofile tests 40 do 41 -- dofile consumes cpu and memory to load the string 42 43 local ctx, m = runtime.callcontext({kill={memory=100000}}, dofile, "lua/big.lua.notest") 44 print(ctx, m) 45 --> =done hello 46 47 print(runtime.callcontext({kill={memory=10000}}, dofile, "lua/big.lua.notest")) 48 --> =killed 49 50 local ctx, m = runtime.callcontext({kill={cpu=10000}}, dofile, "lua/big.lua.notest") 51 print(ctx, m) 52 --> =done hello 53 54 print(runtime.callcontext({kill={cpu=1000}}, dofile, "lua/big.lua.notest")) 55 --> =killed 56 end