[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Does a function exist?
- From: "Aaron Brown" <aaron-lua@...>
- Date: Fri, 19 Nov 2004 21:36:00 -0500
Philip Plumlee:
> How do I query into the global namespace to learn if a
> given function exists?
Erik Hougaard:
> if myfunction then
> print("It exists!!")
> end
Also, if you want to do this without knowing the name until
runtime, you can do this:
if getfenv()[funcname] then
print("'" .. funcname .. "' exists!!")
end
(If necessary, check the type to make sure it's a function
and not something else. If the environment hasn't been
reset, you can also write _G[funcname].)
--
Aaron