From ab59c5afdb8c3c27610af69ddb12c1da585ebc30 Mon Sep 17 00:00:00 2001 From: Victor Date: Sat, 11 Nov 2023 18:38:00 +0300 Subject: [PATCH] module function --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index b6ccecf8a8..3fc990f044 100644 --- a/README.markdown +++ b/README.markdown @@ -731,7 +731,7 @@ instead of the old deprecated form: ```lua - require('xxx') + module('xxx') ``` Here is the reason: by design, the global environment has exactly the same lifetime as the Nginx request handler associated with it. Each request handler has its own set of Lua global variables and that is the idea of request isolation. The Lua module is actually loaded by the first Nginx request handler and is cached by the `require()` built-in in the `package.loaded` table for later reference, and the `module()` builtin used by some Lua modules has the side effect of setting a global variable to the loaded module table. But this global variable will be cleared at the end of the request handler, and every subsequent request handler all has its own (clean) global environment. So one will get Lua exception for accessing the `nil` value.