Hello openresty world,
I have a question around the idea of using closure factory for user scripts in the Lua nginx module.
Current design is to wrap the user script in a closure factory and store this compiled closure factory in a cache table.
lua_load() is performed on "return function() ...user script... end"
When the http request triggers Lua module, the cache table is looked and a lua_pcall() is made on the above which basically returns a function to be executed. Now the lua module calls lua_resume() to execute the user script.
My question is: what do we loose if we do not wrap the user script in the closure factory i.e.
lua_load/luaL_loadstring is performed on "...user script..."
and we store the returned function of lua_load/luaL_loadstring in the cache table.
When http request triggers Lua module, the cache table is looked up and the function over user script is returned without a need to perform lua_pcall().
What is the difference between the two approaches in the context of the Lua module?
Thanks in advance for clarifications.
Best,