lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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