From 591a917e215b63628efc67db042367090ea89655 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Sat, 24 May 2014 16:39:35 -0400 Subject: [PATCH] performance improvement cache type() check of node/function/model, always check if it's string before trying to execute that string as a function. --- plants_lib/init.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plants_lib/init.lua b/plants_lib/init.lua index 1c698eb..3138dd1 100644 --- a/plants_lib/init.lua +++ b/plants_lib/init.lua @@ -182,14 +182,16 @@ function plantslib:search_for_surfaces(minp, maxp, biomedef, node_or_function_or minetest.remove_node(pos) end - if type(node_or_function_or_model) == "table" then + objtype = type(node_or_function_or_model) + + if objtype == "table" then plantslib:generate_tree(pos, node_or_function_or_model) spawned = true - elseif type(node_or_function_or_model) == "string" and + elseif objtype == "string" and minetest.registered_nodes[node_or_function_or_model] then minetest.add_node(p_top, { name = node_or_function_or_model }) spawned = true - elseif pcall(loadstring(("return %s(%s)"): + elseif objtype == "string" and pcall(loadstring(("return %s(%s)"): format(node_or_function_or_model, dump_pos(pos)))) then spawned = true else