1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Add minetest.safe_write_file() to script API

This commit is contained in:
sfan5 2017-11-07 11:46:06 +01:00
parent 9526c68699
commit b692454f70
3 changed files with 25 additions and 0 deletions

View file

@ -357,6 +357,23 @@ int ModApiUtil::l_get_dir_list(lua_State *L)
return 1;
}
// safe_file_write(path, content)
int ModApiUtil::l_safe_file_write(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
const char *path = luaL_checkstring(L, 1);
size_t size;
const char *content = luaL_checklstring(L, 2, &size);
CHECK_SECURE_PATH(L, path, true);
bool ret = fs::safeWriteToFile(path, std::string(content, size));
lua_pushboolean(L, ret);
return 1;
}
// request_insecure_environment()
int ModApiUtil::l_request_insecure_environment(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
@ -476,6 +493,7 @@ void ModApiUtil::Initialize(lua_State *L, int top)
API_FCT(mkdir);
API_FCT(get_dir_list);
API_FCT(safe_file_write);
API_FCT(request_insecure_environment);