better way to test for valid function name in generate call, by SoniEx2

This commit is contained in:
Vanessa Ezekowitz 2014-05-16 16:39:32 -04:00
parent 5eb48a2c67
commit 6b65eeb1fb

View File

@ -190,8 +190,8 @@ function plantslib:search_for_surfaces(minp, maxp, biomedef, node_or_function_or
minetest.registered_nodes[node_or_function_or_model] then minetest.registered_nodes[node_or_function_or_model] then
minetest.add_node(p_top, { name = node_or_function_or_model }) minetest.add_node(p_top, { name = node_or_function_or_model })
spawned = true spawned = true
elseif type(loadstring("return "..node_or_function_or_model)) == "function" then elseif pcall(loadstring(("return type(%s) == \"function\" and %s(%s)"):
assert(loadstring(node_or_function_or_model.."("..dump_pos(pos)..")"))() format(node_or_function_or_model, node_or_function_or_model, dump_pos(pos)))) then
spawned = true spawned = true
else else
print("Ignored invalid definition for object "..dump(node_or_function_or_model).." that was pointed at {"..dump(pos).."}") print("Ignored invalid definition for object "..dump(node_or_function_or_model).." that was pointed at {"..dump(pos).."}")