You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
738 B

--[[
wowmock - WoW environment mock
Copyright 2014 Adirelle (adirelle@gmail.com)
See LICENSE for usage.
--]]
local wowlua = require('wowlua')
local cache = {}
return function(path, globals, ...)
local env = {}
if globals then
setmetatable(env, {
__index = function(self, name)
local value = wowlua[name]
if value == nil then
value = globals[name]
end
self[name] = value
return value
end
})
else
setmetatable(env, { __index = wowlua })
end
env._G = env
local chunk = cache[path]
if not chunk then
local msg
chunk, msg = loadfile(path)
if not chunk then
error(msg, 2)
end
cache[path] = chunk
end
setfenv(chunk, env)
return chunk(...)
end