From 6b65eeb1fbce630a6c3901be9f4d1cedbb684793 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Fri, 16 May 2014 16:39:32 -0400 Subject: [PATCH] better way to test for valid function name in generate call, by SoniEx2 --- plants_lib/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plants_lib/init.lua b/plants_lib/init.lua index a8bddd0..88d776a 100644 --- a/plants_lib/init.lua +++ b/plants_lib/init.lua @@ -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.add_node(p_top, { name = node_or_function_or_model }) spawned = true - elseif type(loadstring("return "..node_or_function_or_model)) == "function" then - assert(loadstring(node_or_function_or_model.."("..dump_pos(pos)..")"))() + elseif pcall(loadstring(("return type(%s) == \"function\" and %s(%s)"): + format(node_or_function_or_model, node_or_function_or_model, dump_pos(pos)))) then spawned = true else print("Ignored invalid definition for object "..dump(node_or_function_or_model).." that was pointed at {"..dump(pos).."}")