github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/lib/iolib/lua/safeio.quotas.lua (about) 1 -- When iosafe is on, functions opening files return errors 2 3 runtime.callcontext({flags="iosafe"}, function() 4 5 -- io module funtions are unavailable 6 7 print(pcall(io.open, "foo.txt")) 8 --> ~false\t.*: safeio: operation not allowed 9 10 print(pcall(io.input, "foo.txt")) 11 --> ~false\t.*: safeio: operation not allowed 12 13 print(pcall(io.lines, "foo.txt")) 14 --> ~false\t.*: safeio: operation not allowed 15 16 print(pcall(io.output, "foo.txt")) 17 --> ~false\t.*: safeio: operation not allowed 18 19 print(pcall(io.tmpfile)) 20 --> ~false\t.*: safeio: operation not allowed 21 22 end) 23 24 -- But functions operating on open files still work 25 26 local f = io.open("files/hello.txt") 27 28 runtime.callcontext({flags="iosafe"}, function() 29 for line in f:lines() do 30 print(line) 31 end 32 --> =bonjour 33 f:seek("set") 34 print(f:read(5)) 35 --> =bonjo 36 f:close() 37 end) 38 39 local f = io.open("files/writetest-safeio.txt", "w") 40 runtime.callcontext({flags="iosafe"}, function() 41 f:write("some text"):flush():close() 42 end) 43 44 print(io.open("files/writetest-safeio.txt", "r"):read("a")) 45 --> =some text