Skip to content

Commit 05ab997

Browse files
committedMay 16, 2015
Add core.mkdir
1 parent 3a8c788 commit 05ab997

File tree

3 files changed

+49
-33
lines changed

3 files changed

+49
-33
lines changed
 

Diff for: ‎doc/lua_api.txt

+29-32
Original file line numberDiff line numberDiff line change
@@ -1674,36 +1674,36 @@ Helper functions
16741674
* Useful for storing custom data
16751675
* `minetest.is_singleplayer()`
16761676
* `minetest.features`
1677-
* table containing API feature flags: `{foo=true, bar=true}`
1677+
* Table containing API feature flags: `{foo=true, bar=true}`
16781678
* `minetest.has_feature(arg)`: returns `boolean, missing_features`
16791679
* `arg`: string or table in format `{foo=true, bar=true}`
16801680
* `missing_features`: `{foo=true, bar=true}`
1681-
* `minetest.get_player_information(playername)`
1682-
* table containing information about player peer.
1683-
1684-
Example of `minetest.get_player_information` return value:
1685-
1686-
{
1687-
address = "127.0.0.1", -- IP address of client
1688-
ip_version = 4, -- IPv4 / IPv6
1689-
min_rtt = 0.01, -- minimum round trip time
1690-
max_rtt = 0.2, -- maximum round trip time
1691-
avg_rtt = 0.02, -- average round trip time
1692-
min_jitter = 0.01, -- minimum packet time jitter
1693-
max_jitter = 0.5, -- maximum packet time jitter
1694-
avg_jitter = 0.03, -- average packet time jitter
1695-
connection_uptime = 200, -- seconds since client connected
1696-
1697-
-- following information is available on debug build only!!!
1698-
-- DO NOT USE IN MODS
1699-
--ser_vers = 26, -- serialization version used by client
1700-
--prot_vers = 23, -- protocol version used by client
1701-
--major = 0, -- major version number
1702-
--minor = 4, -- minor version number
1703-
--patch = 10, -- patch version number
1704-
--vers_string = "0.4.9-git", -- full version string
1705-
--state = "Active" -- current client state
1706-
}
1681+
* `minetest.get_player_information(player_name)`: returns a table containing
1682+
information about player. Example return value:
1683+
{
1684+
address = "127.0.0.1", -- IP address of client
1685+
ip_version = 4, -- IPv4 / IPv6
1686+
min_rtt = 0.01, -- minimum round trip time
1687+
max_rtt = 0.2, -- maximum round trip time
1688+
avg_rtt = 0.02, -- average round trip time
1689+
min_jitter = 0.01, -- minimum packet time jitter
1690+
max_jitter = 0.5, -- maximum packet time jitter
1691+
avg_jitter = 0.03, -- average packet time jitter
1692+
connection_uptime = 200, -- seconds since client connected
1693+
1694+
-- following information is available on debug build only!!!
1695+
-- DO NOT USE IN MODS
1696+
--ser_vers = 26, -- serialization version used by client
1697+
--prot_vers = 23, -- protocol version used by client
1698+
--major = 0, -- major version number
1699+
--minor = 4, -- minor version number
1700+
--patch = 10, -- patch version number
1701+
--vers_string = "0.4.9-git", -- full version string
1702+
--state = "Active" -- current client state
1703+
}
1704+
* `minetest.mkdir(path)`: returns success.
1705+
* Creates a directory specified by `path`, creating parent directories
1706+
if they don't exist.
17071707

17081708
### Logging
17091709
* `minetest.debug(line)`
@@ -2282,11 +2282,8 @@ These functions return the leftover itemstack.
22822282
the floor or ceiling
22832283
* The first four options are mutually-exclusive; the last in the list takes
22842284
precedence over the first.
2285-
2286-
2287-
22882285
* `minetest.rotate_node(itemstack, placer, pointed_thing)`
2289-
* calls `rotate_and_place()` with infinitestacks set according to the state of
2286+
* calls `rotate_and_place()` with infinitestacks set according to the state of
22902287
the creative mode setting, and checks for "sneak" to set the `invert_wall`
22912288
parameter.
22922289

@@ -2306,7 +2303,7 @@ minetest.global_exists(name)
23062303
* Any function in the minetest namespace can be called using the syntax
23072304
`minetest.env:somefunction(somearguments)`
23082305
instead of `minetest.somefunction(somearguments)`
2309-
* Deprecated, but support is not to be dropped soon
2306+
* Deprecated, but support is not to be dropped soon
23102307

23112308
### Global tables
23122309
* `minetest.registered_items`

Diff for: ‎src/script/lua_api/l_util.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2424
#include "cpp_api/s_async.h"
2525
#include "serialization.h"
2626
#include "json/json.h"
27+
#include "cpp_api/s_security.h"
2728
#include "debug.h"
2829
#include "porting.h"
2930
#include "log.h"
@@ -327,6 +328,17 @@ int ModApiUtil::l_decompress(lua_State *L)
327328
return 1;
328329
}
329330

331+
// mkdir(path)
332+
int ModApiUtil::l_mkdir(lua_State *L)
333+
{
334+
NO_MAP_LOCK_REQUIRED;
335+
const char *path = luaL_checkstring(L, 1);
336+
CHECK_SECURE_PATH_OPTIONAL(L, path);
337+
lua_pushboolean(L, fs::CreateAllDirs(path));
338+
return 1;
339+
}
340+
341+
330342
void ModApiUtil::Initialize(lua_State *L, int top)
331343
{
332344
API_FCT(debug);
@@ -352,6 +364,8 @@ void ModApiUtil::Initialize(lua_State *L, int top)
352364

353365
API_FCT(compress);
354366
API_FCT(decompress);
367+
368+
API_FCT(mkdir);
355369
}
356370

357371
void ModApiUtil::InitializeAsync(AsyncEngine& engine)
@@ -374,5 +388,7 @@ void ModApiUtil::InitializeAsync(AsyncEngine& engine)
374388

375389
ASYNC_API_FCT(compress);
376390
ASYNC_API_FCT(decompress);
391+
392+
ASYNC_API_FCT(mkdir);
377393
}
378394

Diff for: ‎src/script/lua_api/l_util.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class ModApiUtil : public ModApiBase {
7878
// is_yes(arg)
7979
static int l_is_yes(lua_State *L);
8080

81-
// get_scriptdir()
81+
// get_builtin_path()
8282
static int l_get_builtin_path(lua_State *L);
8383

8484
// compress(data, method, ...)
@@ -87,6 +87,9 @@ class ModApiUtil : public ModApiBase {
8787
// decompress(data, method, ...)
8888
static int l_decompress(lua_State *L);
8989

90+
// mkdir(path)
91+
static int l_mkdir(lua_State *L);
92+
9093
public:
9194
static void Initialize(lua_State *L, int top);
9295

0 commit comments

Comments
 (0)