diff options
author | kwolekr <kwolekr@minetest.net> | 2015-09-23 00:31:45 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2015-09-23 15:56:24 -0400 |
commit | f062bbd7a182233f96c61287d0397534811627d9 (patch) | |
tree | df3d2252f8bbb9975669c7920b57dce2fb3d3df6 /builtin/common | |
parent | 596484da4fcd301e597a851a9a54b6dc276a286a (diff) | |
download | minetest-f062bbd7a182233f96c61287d0397534811627d9.tar.gz minetest-f062bbd7a182233f96c61287d0397534811627d9.tar.bz2 minetest-f062bbd7a182233f96c61287d0397534811627d9.zip |
Add /emergeblocks command and core.emerge_area() Lua API
Diffstat (limited to 'builtin/common')
-rw-r--r-- | builtin/common/misc_helpers.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index bf672e6da..08a230431 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -555,6 +555,36 @@ assert(core.string_to_pos("( 10.0, 5, -2)").z == -2) assert(core.string_to_pos("asd, 5, -2)") == nil) -------------------------------------------------------------------------------- +function core.string_to_area(value) + local p1, p2 = unpack(value:split(") (")) + if p1 == nil or p2 == nil then + return nil + end + + p1 = core.string_to_pos(p1 .. ")") + p2 = core.string_to_pos("(" .. p2) + if p1 == nil or p2 == nil then + return nil + end + + return p1, p2 +end + +local function test_string_to_area() + local p1, p2 = core.string_to_area("(10.0, 5, -2) ( 30.2, 4, -12.53)") + assert(p1.x == 10.0 and p1.y == 5 and p1.z == -2) + assert(p2.x == 30.2 and p2.y == 4 and p2.z == -12.53) + + p1, p2 = core.string_to_area("(10.0, 5, -2 30.2, 4, -12.53") + assert(p1 == nil and p2 == nil) + + p1, p2 = core.string_to_area("(10.0, 5,) -2 fgdf2, 4, -12.53") + assert(p1 == nil and p2 == nil) +end + +test_string_to_area() + +-------------------------------------------------------------------------------- function table.copy(t, seen) local n = {} seen = seen or {} |