How to use files in lua

Post Reply
LC Creations
Member
Posts: 150
Joined: Mon Feb 18, 2019 02:53

How to use files in lua

by LC Creations » Post

How do you load file in lua? I tried this and Minetest would not let the mod work. It was saying that it is forbidden to do that or something while loading the world with the mod. Thanks. I dont usually use lua so I forgot the code I used.

ThorfinnS
Member
Posts: 288
Joined: Mon Feb 25, 2019 22:05
GitHub: ThorfinnS

Re: How to use files in lua

by ThorfinnS » Post

Are you trying to write something in a directory other than the mod's own directory? I'm not sure what other circumstances give a similar error. Maybe post what it is you are doing, the directory you installed in, and the exact error message. That would be more helpful than just guessing.

User avatar
Linuxdirk
Member
Posts: 2713
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: How to use files in lua

by Linuxdirk » Post

LC Creations wrote:How do you load file in lua?
dofile('path') for loading Lua files or io.open('path', 'mode') for opening files (mode r for reading, mode w for writing)
LC Creations wrote:It was saying that it is forbidden to do that or something
Provide your code and a proper error message. This would help people to understand your issue.

Eran
Member
Posts: 123
Joined: Fri May 03, 2019 16:46

Re: How to use files in lua

by Eran » Post

This sounds like mod security in action.
Minetest has security mechanisms which prevent io.open and some other functions from accessing files outside of your world folder and your mod folder (I think, didn't try it). Maybe there's also some other place you're allowed to access that I don't know of. minetest.get_worldpath and minetest.get_modpath are functions you can use to get these paths.
If you absolutely need to access files protected by mod security, look into insecure environments. If you just want to store data, there are ways in minetest without accessing files yourself. https://rubenwardy.com/minetest_modding ... orage.html

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests