diff options
author | RealBadAngel <maciej.kasatkin@o2.pl> | 2014-07-03 17:40:06 +0200 |
---|---|---|
committer | RealBadAngel <maciej.kasatkin@o2.pl> | 2014-07-03 17:40:06 +0200 |
commit | 0e6b3ce86b6993012c217e32bc2c0370340480c5 (patch) | |
tree | d09e4c025566886c8d9c273cf6583dc9413acd54 | |
parent | 5727a84bd8c2e71704dda1bfaa8e581755451ac6 (diff) |
Add snippet to check if function exists.
-rw-r--r-- | technic/helpers.lua | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/technic/helpers.lua b/technic/helpers.lua index 624a8a7..14c4a30 100644 --- a/technic/helpers.lua +++ b/technic/helpers.lua @@ -25,3 +25,21 @@ function technic.refill_RE_charge(stack) stack:set_metadata(minetest.serialize(meta)) return stack end + + -------------------------------------------------------------------------------- +local function resolve_name(function_name) + local a = _G + for key in string.gmatch(function_name, "([^%.]+)(%.?)") do + if a[key] then + a = a[key] + else + return nil + end + end + return a +end + +function technic.function_exists(function_name) + return type(resolve_name(function_name)) == 'function' +end +-------------------------------------------------------------------------------- |