Skip to content

Commit b6f4b73

Browse files
committed
doc: how to call modulefile commands in hook proc
Fixes #590 Signed-off-by: Xavier Delaruelle <[email protected]>
1 parent 19d4157 commit b6f4b73

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

doc/source/module.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3844,6 +3844,21 @@ adds a new query option to the :mfcmd:`module-info` modulefile command:
38443844
}
38453845
}
38463846
3847+
If a hook procedure needs to execute modulefile commands (for example, to
3848+
define environment variables), these commands should be run through the
3849+
current modulefile Tcl interpreter. This ensures that the commands behave
3850+
consistently with the current modulefile evaluation mode.
3851+
3852+
.. code-block:: tcl
3853+
3854+
proc hook_procedure {value} {
3855+
# get the name of the current modulefile Tcl interpreter
3856+
set modfile_interp [getCurrentModfileInterpName]
3857+
3858+
# execute a modulefile command in the current interpreter context
3859+
interp eval $modfile_interp setenv MYVAR $value
3860+
}
3861+
38473862
Siteconfig hook variables
38483863
"""""""""""""""""""""""""
38493864

0 commit comments

Comments
 (0)