@@ -22,7 +22,7 @@ local CODE_ENTITIES = {
2222}
2323
2424local caching , ngx_var , ngx_capture , ngx_null = true
25- local template = { cache = {}, concat = concat }
25+ local template = { _VERSION = " 1.1 " , cache = {}, concat = concat }
2626
2727local function read_file (path )
2828 local file = open (path , " rb" )
5858 template .load = load_lua
5959end
6060
61- local context = setmetatable ({ context = {}, blocks = {}, template = template }, {
62- __index = function (t , k )
63- return t .context [k ] or t .template [k ] or _G [k ]
64- end
65- })
66-
61+ local context = { context = {}, blocks = {}, template = template }
6762local load_chunk
6863
69- if _VERSION == " Lua 5.1" and type (jit ) ~= " table" then
70- load_chunk = function (view )
71- local func = assert (loadstring (view ))
72- setfenv (func , context )
73- return func
64+ if _VERSION == " Lua 5.1" then
65+ setmetatable (context , { __index = function (t , k )
66+ return t .context [k ] or t .template [k ] or _G [k ]
67+ end })
68+ if jit then
69+ load_chunk = function (view )
70+ return assert (load (view , nil , " tb" , context ))
71+ end
72+ else
73+ load_chunk = function (view )
74+ local func = assert (loadstring (view ))
75+ setfenv (func , context )
76+ return func
77+ end
7478 end
7579else
80+ setmetatable (context , { __index = function (t , k )
81+ return t .context [k ] or t .template [k ] or _ENV [k ]
82+ end })
7683 load_chunk = function (view )
7784 return assert (load (view , nil , " tb" , context ))
7885 end
0 commit comments