Skip to content

Instantly share code, notes, and snippets.

@seebs
Created September 28, 2014 02:51
Show Gist options
  • Save seebs/99c1c4c64e6cbb4eada3 to your computer and use it in GitHub Desktop.
Save seebs/99c1c4c64e6cbb4eada3 to your computer and use it in GitHub Desktop.
local passnouns = { 'Loc', 'Rot', 'Scl', 'Color' }
local anim_safe_data = {}
setmetatable(anim_safe_data, { __mode = 'k' })
local animverbs = { 'seek', 'move' }
function Util.animsafe(obj)
if anim_safe_data[obj] then
return
end
local d = {}
local f = {}
anim_safe_data[obj] = true
for i = 1, #passnouns do
local noun = passnouns[i]
for j = 1, #animverbs do
local name = animverbs[j] .. noun
f[name] = obj[name]
obj[name] = function(...)
if d[noun] then
d[noun]:stop()
end
d[noun] = f[name](...)
return d[noun]
end
end
local name = 'set' .. noun
f[name] = obj[name]
obj[name] = function(...)
if d[noun] then
d[noun]:stop()
d[noun] = nil
end
-- set doesn't return a value, so no need to stash it
return f[name](...)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment