diff --git a/elua.moon b/elua.moon index f24c86d..9d2cb82 100644 --- a/elua.moon +++ b/elua.moon @@ -132,7 +132,12 @@ class Parser fn = assert load(code_fn, name) (env={}) -> - setfenv fn, env + combined_env = setmetatable {}, __index: (name) => + val = env[name] + val = _G[name] if val == nil + val + + setfenv fn, combined_env fn tostring, concat, html_escape -- generates the code of the template diff --git a/spec/elua_spec.moon b/spec/elua_spec.moon index 496fac8..1f32bc2 100644 --- a/spec/elua_spec.moon +++ b/spec/elua_spec.moon @@ -78,6 +78,13 @@ This is my message to <%= [=[oh yeah %>"]=] %>]] " } + + -- should have access to _G + { + "" + "<% assert(true) %>" + { hello: "world" } + } } for case in *cases