Skip to content

Instantly share code, notes, and snippets.

@kevinw
Created January 28, 2013 20:24
Show Gist options
  • Save kevinw/4658681 to your computer and use it in GitHub Desktop.
Save kevinw/4658681 to your computer and use it in GitHub Desktop.
local script = function()
wait(5)
end
local scriptFuncs = {
wait = function(secs)
print (entity, 'is waiting', secs)
assert(entity ~= nil) -- FAILS HERE
end,
}
function execWithContext(entity)
local env = {entity=entity}
for key, func in pairs(scriptFuncs) do env[key] = func end
setmetatable(env, {__index = _G})
setfenv(script, env)
script()
end
local myEntity = "ENTITY1"
execWithContext(myEntity)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment