From a4183994a446a065e3151745b4167270ebae6194 Mon Sep 17 00:00:00 2001
From: Sfan5 <sfan5@live.de>
Date: Wed, 1 May 2013 12:31:21 +0200
Subject: [PATCH] Add a Way of checking for specific Feature with Lua Adds
 minetest.get_feature() and minetest.has_feature()

---
 builtin/builtin.lua  |  1 +
 builtin/features.lua | 28 ++++++++++++++++++++++++++++
 doc/lua_api.txt      |  5 +++++
 3 files changed, 34 insertions(+)
 create mode 100644 builtin/features.lua

diff --git a/builtin/builtin.lua b/builtin/builtin.lua
index bf33cbe6b..f10c6c7cf 100644
--- a/builtin/builtin.lua
+++ b/builtin/builtin.lua
@@ -24,4 +24,5 @@ dofile(minetest.get_modpath("__builtin").."/chatcommands.lua")
 dofile(minetest.get_modpath("__builtin").."/static_spawn.lua")
 dofile(minetest.get_modpath("__builtin").."/detached_inventory.lua")
 dofile(minetest.get_modpath("__builtin").."/falling.lua")
+dofile(minetest.get_modpath("__builtin").."/features.lua")
 
diff --git a/builtin/features.lua b/builtin/features.lua
new file mode 100644
index 000000000..0eef2519d
--- /dev/null
+++ b/builtin/features.lua
@@ -0,0 +1,28 @@
+-- Minetest: builtin/features.lua
+
+minetest.features = {
+	"glasslike_framed" = true,
+	"nodebox_as_selectionbox" = true,
+	"chat_send_player_param3" = true,
+	"get_all_craft_recipes_works" = true,
+	"use_texture_alpha" = true,
+}
+
+function minetest.has_feature(arg)
+	if type(arg) == "table" then
+		missing_features = {}
+		result = true
+		for ft, _ in pairs(arg) do
+			if not minetest.features[ftr] then
+				missing_features[ftr] = true
+				result = false
+			end
+		end
+		return result, missing_features
+	elseif type(arg) == "string" then
+		if not minetest.features[arg] then
+			return false, {[arg]=true}
+		end
+		return true, {}
+	end
+end
diff --git a/doc/lua_api.txt b/doc/lua_api.txt
index 07fb1ccd6..597f98c2c 100644
--- a/doc/lua_api.txt
+++ b/doc/lua_api.txt
@@ -912,6 +912,11 @@ minetest.get_modnames() -> list of installed mods
 minetest.get_worldpath() -> eg. "/home/user/.minetest/world"
 ^ Useful for storing custom data
 minetest.is_singleplayer()
+minetest.features
+^ table containing API feature flags: {foo=true, bar=true}
+minetest.has_feature(arg) -> bool, missing_features
+^ arg: string or table in format {foo=true, bar=true}
+^ missing_features: {foo=true, bar=true}
 
 minetest.debug(line)
 ^ Always printed to stderr and logfile (print() is redirected here)