mirror of
https://github.com/Reuh/candran.git
synced 2025-10-27 09:59:29 +00:00
Fix #set changing global state
This commit is contained in:
parent
b32d4d5600
commit
56f1901f9b
2 changed files with 251 additions and 245 deletions
10
candran.can
10
candran.can
|
|
@ -53,7 +53,7 @@ end
|
|||
-- @treturn[1] macros registered macros
|
||||
-- @treturn[2] nil nil if error
|
||||
-- @treturn[2] error string error message
|
||||
function candran.preprocess(input, options={})
|
||||
function candran.preprocess(input, options={}, _env)
|
||||
options = util.merge(candran.default, options)
|
||||
local macros = {
|
||||
functions = {},
|
||||
|
|
@ -98,6 +98,7 @@ function candran.preprocess(input, options={})
|
|||
preprocessor ..= "return output"
|
||||
|
||||
-- make preprocessor environement
|
||||
local exportenv = {}
|
||||
local env = util.merge(_G, options.preprocessorEnv)
|
||||
--- Candran library table
|
||||
env.candran = candran
|
||||
|
|
@ -118,8 +119,9 @@ function candran.preprocess(input, options={})
|
|||
|
||||
margs = util.merge(options, { chunkname = filepath, loadLocal = true, loadPackage = true }, margs)
|
||||
margs.import = {} -- no need for recursive import
|
||||
local modcontent, modmacros = assert(candran.preprocess(f:read("*a"), margs))
|
||||
local modcontent, modmacros, modenv = assert(candran.preprocess(f:read("*a"), margs))
|
||||
macros = util.recmerge(macros, modmacros)
|
||||
for k, v in pairs(modenv) do env[k] = v end
|
||||
f:close()
|
||||
|
||||
-- get module name (ex: module name of path.to.module is module)
|
||||
|
|
@ -185,7 +187,7 @@ function candran.preprocess(input, options={})
|
|||
end
|
||||
end
|
||||
env.set = function(identifier, value)
|
||||
options.preprocessorEnv[identifier] = value
|
||||
exportenv[identifier] = value
|
||||
env[identifier] = value
|
||||
end
|
||||
|
||||
|
|
@ -215,7 +217,7 @@ function candran.preprocess(input, options={})
|
|||
return nil, "in preprocessor: "..output
|
||||
end
|
||||
|
||||
return output, macros
|
||||
return output, macros, exportenv
|
||||
end
|
||||
|
||||
--- Run the compiler
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue