mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 23:49:33 +00:00
Optimizes plugins_utils.loadModule with require
This commit is contained in:
parent
1e3fa9a389
commit
36478ba3ee
1 changed files with 7 additions and 6 deletions
|
|
@ -24,6 +24,7 @@ plugins_utils.ENTERPRISE_L_SOURCE_DIR = os_utils.fixPath(dirs.installdir .. "/pr
|
|||
local PLUGIN_RELATIVE_PATHS = {
|
||||
menu_items = "menu_items",
|
||||
metadata = "plugins_metadata",
|
||||
modules = "modules",
|
||||
}
|
||||
local RUNTIME_PATHS = {}
|
||||
local METADATA = nil
|
||||
|
|
@ -930,15 +931,15 @@ end
|
|||
-- @brief Load a module located inside a plugin. This is equivalent to the
|
||||
-- lua "require ..." of the builting ntopng modules
|
||||
function plugins_utils.loadModule(plugin_name, module_name)
|
||||
init_runtime_paths()
|
||||
init_runtime_paths()
|
||||
|
||||
local lua_path = os_utils.fixPath(RUNTIME_PATHS.modules .. "/" .. plugin_name .. "/" .. module_name .. ".lua")
|
||||
lua_path_utils.package_path_preprend(RUNTIME_PATHS.modules)
|
||||
|
||||
if not ntop.exists(lua_path) then
|
||||
return(nil)
|
||||
end
|
||||
local lua_path = os_utils.fixPath(RUNTIME_PATHS.modules .. "/" .. plugin_name .. "/" .. module_name .. ".lua")
|
||||
local req_name = string.format("%s.%s", plugin_name, module_name)
|
||||
local req = require(req_name)
|
||||
|
||||
return dofile(lua_path)
|
||||
return req
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue