Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a file in Lua?

Tags:

lua

I just want to write a file to somewhere. Here is my code:

file = io.open("test.txt", "w")
file:write("Hello World")
file:close()

but the app crashes at the first line with:

attempt to call field 'open' (a nil value)

Even trying with the Lua online console keeps up the same error.

EDITED: Here is my screenshot of the console enter image description here

like image 608
Corbella Avatar asked Apr 13 '26 21:04

Corbella


1 Answers

Try this code to dump the keys of io:

for k in next,io do
  print(k)
end

Lua online outputs:

write

Which makes sense when you think about it:

Sandboxing works by restricting what can be done, including removal of unsafe functions.

like image 146
Deduplicator Avatar answered Apr 17 '26 10:04

Deduplicator



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!