diff options
author | Perttu Ahola <celeron55@gmail.com> | 2012-04-09 23:29:55 +0300 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2012-04-09 23:32:13 +0300 |
commit | 93cdc9b9dc240aef70ec5016552c7f36ee019865 (patch) | |
tree | 55157b777205cb9891fa7dd567cb2fe21e6c88fc /builtin/misc.lua | |
parent | 8ed74a342988b7d67a7c9eacc2257ba42acd00de (diff) | |
download | minetest-93cdc9b9dc240aef70ec5016552c7f36ee019865.tar.gz minetest-93cdc9b9dc240aef70ec5016552c7f36ee019865.tar.bz2 minetest-93cdc9b9dc240aef70ec5016552c7f36ee019865.zip |
Support static_spawnpoint setting
Diffstat (limited to 'builtin/misc.lua')
-rw-r--r-- | builtin/misc.lua | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/builtin/misc.lua b/builtin/misc.lua index 89f90dfbd..b3b1ec6e8 100644 --- a/builtin/misc.lua +++ b/builtin/misc.lua @@ -67,3 +67,35 @@ function minetest.get_node_group(name, group) return minetest.get_item_group(name, group) end +function minetest.string_to_pos(value) + local p = {} + p.x, p.y, p.z = string.match(value, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$") + if p.x and p.y and p.z then + p.x = tonumber(p.x) + p.y = tonumber(p.y) + p.z = tonumber(p.z) + return p + end + local p = {} + p.x, p.y, p.z = string.match(value, "^%( *([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+) *%)$") + if p.x and p.y and p.z then + p.x = tonumber(p.x) + p.y = tonumber(p.y) + p.z = tonumber(p.z) + return p + end + return nil +end + +assert(minetest.string_to_pos("10.0, 5, -2").x == 10) +assert(minetest.string_to_pos("( 10.0, 5, -2)").z == -2) +assert(minetest.string_to_pos("asd, 5, -2)") == nil) + +function minetest.setting_get_pos(name) + local value = minetest.setting_get(name) + if not value then + return nil + end + return minetest.string_to_pos(value) +end + |