diff options
author | kwolekr <kwolekr@minetest.net> | 2013-03-24 15:29:23 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2013-03-24 15:40:53 -0400 |
commit | 0e07a7157f4865c26b4d7d0ba6fb12f1de59373c (patch) | |
tree | 490531f6fabef104d1f214bd1dc29e0be7b878e5 /src/scriptapi.cpp | |
parent | 423d69bd4095970068b5431b4b33007a3c069576 (diff) | |
download | minetest-0e07a7157f4865c26b4d7d0ba6fb12f1de59373c.tar.gz minetest-0e07a7157f4865c26b4d7d0ba6fb12f1de59373c.tar.bz2 minetest-0e07a7157f4865c26b4d7d0ba6fb12f1de59373c.zip |
Add more error checking to l_register_ore
Diffstat (limited to 'src/scriptapi.cpp')
-rw-r--r-- | src/scriptapi.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index ddffbb0b7..80abffa2b 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -704,11 +704,16 @@ static int l_register_ore(lua_State *L) enum OreType oretype = (OreType)getenumfield(L, index, "ore_type", es_OreType, ORE_SCATTER); Ore *ore = createOre(oretype); + if (!ore) { + errorstream << "register_ore: ore_type " + << oretype << " not implemented"; + return 0; + } ore->ore_name = getstringfield_default(L, index, "ore", ""); ore->wherein_name = getstringfield_default(L, index, "wherein", ""); - ore->clust_scarcity = getintfield_default(L, index, "clust_scarcity", 0); - ore->clust_num_ores = getintfield_default(L, index, "clust_num_ores", 0); + ore->clust_scarcity = getintfield_default(L, index, "clust_scarcity", 1); + ore->clust_num_ores = getintfield_default(L, index, "clust_num_ores", 1); ore->clust_size = getintfield_default(L, index, "clust_size", 0); ore->height_min = getintfield_default(L, index, "height_min", 0); ore->height_max = getintfield_default(L, index, "height_max", 0); @@ -720,6 +725,13 @@ static int l_register_ore(lua_State *L) ore->noise = NULL; + if (ore->clust_scarcity <= 0 || ore->clust_num_ores <= 0) { + errorstream << "register_ore: clust_scarcity and clust_num_ores" + "must be greater than 0"; + delete ore; + return 0; + } + emerge->ores.push_back(ore); verbosestream << "register_ore: ore '" << ore->ore_name |