nginxdynamicluaevaluationopenresty

How to load module using a variable with Lua in Openresty?


Trying to load modules based on a value in a variable. Is this possible?

local moduletoload = "login"    
local mod_action = require moduletoload

Thanks


Solution

  • When the argument is a string or table, you can omit parentheses, which is specified by Lua, but in other cases parentheses must be used.

    local mod_action = require(moduletoload)