# HG changeset patch
# User Matthew Wild <mwild1@gmail.com>
# Date 1335045135 -3600
# Node ID d1739d72100af1c0411707af063d44e6405149ec
# Parent  464ca74ddf6ad145ac6f690ad7a0048e54d70130
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)

diff -r 464ca74ddf6a -r d1739d72100a core/moduleapi.lua
--- a/core/moduleapi.lua	Sat Apr 21 22:50:57 2012 +0100
+++ b/core/moduleapi.lua	Sat Apr 21 22:52:15 2012 +0100
@@ -135,6 +135,7 @@
 -- Intentionally does not allow the table at a path to be _set_, it
 -- is auto-created if it does not exist.
 function api:shared(...)
+	if not self.shared_data then self.shared_data = {}; end
 	local paths = { n = select("#", ...), ... };
 	local data_array = {};
 	local default_path_components = { self.host, self.name };
@@ -150,6 +151,7 @@
 			shared_data[path] = shared;
 		end
 		t_insert(data_array, shared);
+		self.shared_data[path] = shared;
 	end
 	return unpack(data_array);
 end