Software /
code /
prosody
Comparison
core/moduleapi.lua @ 4651:d1739d72100a
moduleapi: Have modules internally store a reference to shared tables they use, to ensure they don't get collected while any module that had access to that table is still loaded (thanks Zash)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 21 Apr 2012 22:52:15 +0100 |
parent | 4614:20940729c1b4 |
child | 4660:96b40b5e8ea8 |
comparison
equal
deleted
inserted
replaced
4650:464ca74ddf6a | 4651:d1739d72100a |
---|---|
133 | 133 |
134 -- Returns one or more shared tables at the specified virtual paths | 134 -- Returns one or more shared tables at the specified virtual paths |
135 -- Intentionally does not allow the table at a path to be _set_, it | 135 -- Intentionally does not allow the table at a path to be _set_, it |
136 -- is auto-created if it does not exist. | 136 -- is auto-created if it does not exist. |
137 function api:shared(...) | 137 function api:shared(...) |
138 if not self.shared_data then self.shared_data = {}; end | |
138 local paths = { n = select("#", ...), ... }; | 139 local paths = { n = select("#", ...), ... }; |
139 local data_array = {}; | 140 local data_array = {}; |
140 local default_path_components = { self.host, self.name }; | 141 local default_path_components = { self.host, self.name }; |
141 for i = 1, paths.n do | 142 for i = 1, paths.n do |
142 local path = paths[i]; | 143 local path = paths[i]; |
148 if not shared then | 149 if not shared then |
149 shared = {}; | 150 shared = {}; |
150 shared_data[path] = shared; | 151 shared_data[path] = shared; |
151 end | 152 end |
152 t_insert(data_array, shared); | 153 t_insert(data_array, shared); |
154 self.shared_data[path] = shared; | |
153 end | 155 end |
154 return unpack(data_array); | 156 return unpack(data_array); |
155 end | 157 end |
156 | 158 |
157 function api:get_option(name, default_value) | 159 function api:get_option(name, default_value) |