diff options
author | Matthew Cline <zelgadis@sourceforge.net> | 2009-10-22 03:53:05 -0700 |
---|---|---|
committer | Matthew Cline <zelgadis@sourceforge.net> | 2009-10-22 03:53:05 -0700 |
commit | 49870f2bc48989467ea4f8c847fd1274cec73944 (patch) | |
tree | 050245a946eb520236d028cec8c661743c76d501 /crawl-ref/source/dat/clua/util.lua | |
parent | a724290e7ae62bc20013919bc14c16e91d842083 (diff) | |
download | crawl-ref-49870f2bc48989467ea4f8c847fd1274cec73944.tar.gz crawl-ref-49870f2bc48989467ea4f8c847fd1274cec73944.zip |
Observerable/observer-ish pattern for Lua markers
A new framework for Lua markers, similar to the observable/observer
design pattern, which decouples the thing being activated from the thing
watching for the activating condition. This makes it easier to create
new types of Lua markers which are triggered by dungeon events, and
easier to add new triggering conditions to already existing marker
types. Currently only ChangeFlags (clua/lm_flags.lua) and
MonsterOnTrigger (clua/lm_monst.lua) use it.
Diffstat (limited to 'crawl-ref/source/dat/clua/util.lua')
-rw-r--r-- | crawl-ref/source/dat/clua/util.lua | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/crawl-ref/source/dat/clua/util.lua b/crawl-ref/source/dat/clua/util.lua index 4894f1fc67..1ed3670172 100644 --- a/crawl-ref/source/dat/clua/util.lua +++ b/crawl-ref/source/dat/clua/util.lua @@ -306,3 +306,23 @@ function table_to_string(table, depth) return str end + +-- Copied from http://lua-users.org/wiki/CopyTable +function util.copy_table(object) + local lookup_table = {} + local function _copy(object) + if type(object) ~= "table" then + return object + elseif lookup_table[object] then + return lookup_table[object] + end + local new_table = {} + lookup_table[object] = new_table + for index, value in pairs(object) do + new_table[_copy(index)] = _copy(value) + end + return setmetatable(new_table, getmetatable(object)) + end + return _copy(object) +end + |