Advertisement
alestane

Untitled

Dec 19th, 2011
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function newMonitoredVariable(name, value)
  2.     Runtime:dispatchEvent{name="Variable"; variable=name, value=value}
  3.     return function(...)
  4.         if select('#', ...) == 0 then
  5.             return value
  6.         end
  7.         local old = value
  8.         value = ...
  9.         Runtime:dispatchEvent{name="Variable"; variable=name, value=value, oldValue=old}
  10.         return old
  11.     end
  12. end
  13.  
  14. Runtime:addEventListener("Variable", function (event) _G[event.variable] = event.value end)
  15.  
  16. set_fnord = newMonitoredVariable("fnord", 5)
  17.  
  18. print(fnord) -- prints 5
  19.  
  20. set_fnord("kumquat")
  21.  
  22. print(fnord) -- prints kumquat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement