Let's say, I define a dynamic variable *a*
inside a module m1
. Then I mount-module m1
in a m2
module:
(in-package m2)
(mount-module sub (#:m1)
(m1:*a* 3))
How can I get the value 3 now from the module m2
? For example, currently, I have to hack it in a such way:
(restas:with-context
(second (gethash 'm1
(gethash
:modules
(gethash (find-package :m2)
restas::*pkgmodules-traits*))))
m1:*a*))
Which is, certainly, not even close to a good way.
A slightly better solution is the following:
(defmethod restas:module-context ((module symbol))
(second (gethash module (restas::pkgmodule-traits-modules *package*))))
Then you can access the context for the module with module-context
, for example:
(with-context (module-context 'sub)
m1:*a*)
Or better yet:
(with-module 'sub
m1:*a*)
Note that you use the name you used when mounting the module, not the name of the package you mounted.
UPDATE: The method I described has been added to RESTAS.