lua-users home
lua-l archive

Checking whether a shared library has been loaded

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


I wish to test whether a shared library has already been loaded.
This is the best I can come up with.
is_loaded_library = function (LIB_NAME)
-- returns fully qualified name of loaded library or `false`
 for key,val in pairs(debug.getregistry()) do
 if type(key)=='userdata' and type(val)=='table' then
 for k in pairs(val) do
 if type(k)=='string' and k:match(LIB_NAME..'$') then
 return k
 end
 end
 end
 end
 return false
end
Is there a better way?

AltStyle によって変換されたページ (->オリジナル) /