aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2017-11-07 11:46:06 +0100
committersfan5 <sfan5@live.de>2017-11-08 16:14:05 +0100
commitb692454f70cb661a8ce733a4bcbbadcb5edd0049 (patch)
treead28f1e120d6c10452df9ce342a06002593d3dc6 /src/script/lua_api
parent9526c686997285700f500b975a9d971c3ca0a188 (diff)
downloadminetest-b692454f70cb661a8ce733a4bcbbadcb5edd0049.tar.gz
minetest-b692454f70cb661a8ce733a4bcbbadcb5edd0049.tar.bz2
minetest-b692454f70cb661a8ce733a4bcbbadcb5edd0049.zip
Add minetest.safe_write_file() to script API
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_util.cpp18
-rw-r--r--src/script/lua_api/l_util.h3
2 files changed, 21 insertions, 0 deletions
diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp
index ef4df8182..839c4be11 100644
--- a/src/script/lua_api/l_util.cpp
+++ b/src/script/lua_api/l_util.cpp
@@ -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);
diff --git a/src/script/lua_api/l_util.h b/src/script/lua_api/l_util.h
index e17425d73..4392a4339 100644
--- a/src/script/lua_api/l_util.h
+++ b/src/script/lua_api/l_util.h
@@ -80,6 +80,9 @@ private:
// get_dir_list(path, is_dir)
static int l_get_dir_list(lua_State *L);
+ // safe_file_write(path, content)
+ static int l_safe_file_write(lua_State *L);
+
// request_insecure_environment()
static int l_request_insecure_environment(lua_State *L);