Created
January 28, 2013 20:24
-
-
Save kevinw/4658681 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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