| 1 |
* As we talked about last time the loadModulefile() function knows if the modulefile is a TCL or Lua modulefile |
| 2 |
** How Lmod knows which is which |
| 3 |
(by the *.lua extension or not) |
| 4 |
That is if a modulefile has a *.lua extension it is treated as a Lua |
| 5 |
modulefile. Otherwise it is a TCL modulefile |
| 6 |
Note that Lmod walks the module tree every time or uses the Spider Cache. It knows that a TCL |
| 7 |
modulefile is a TCL modulefile. All non-Lua extension files are |
| 8 |
checked for a #%Module start line. |
| 9 |
** There is a command line style interface between Lmod and tcl2lua.tcl |
| 10 |
The mode of eval: load, remove, display, help) |
| 11 |
The list of currently loaded module |
| 12 |
What the full name and user name are for the module |
| 13 |
Shell type: bash, csh etc |
| 14 |
One tcl modulefile to "load" |
| 15 |
|
| 16 |
** Lmod 8.0+ added support for integrating the TCL interpreter into the Lua executable. |
| 17 |
** Lua supports dynamically linking of *.so. |
| 18 |
** Using this library avoid making a system() call every time to eval a TCL modulefile |
| 19 |
** This is supported by LMOD_FAST_TCL_INTERP |
| 20 |
** You can dynamically control this by changing LMOD_FAST_TCL_INTERP=no etc. |
| 21 |
* Some tricky things: |
| 22 |
* tcl is-loaded needs to be evaluated by tcl2lua because typically used via an if block |
| 23 |
if { [ is-loaded foo ] } { |
| 24 |
# do something |
| 25 |
} |
| 26 |
** Lmod passes the list o currently loaded modules to the tcl2lua.tcl program |
| 27 |
So that the if test can be eval'ed by tcl2lua.tcl |
| 28 |
* Recently (Lmod 8.6+) , support for is-avail |
| 29 |
This one is very tricky and only now supported |
| 30 |
** The problem is that tcl2lua.tcl is a separate code written in tcl |
| 31 |
It does NOT have access to the internal Lmod structures like the |
| 32 |
modules that are available to load |
| 33 |
** Could write a tcl version of this inside tcl2lua.tcl |
| 34 |
But that would be too much work and hard to get right. |
| 35 |
The one-name rule would be difficult to re-work in TCL. |
| 36 |
** Instead the TCl runs "$LMOD_CMD bash --no_redirect -t avail" |
| 37 |
** This generates a list of available module written to stderr |
| 38 |
** This list is processed and stored in a TCL dictionary |
| 39 |
** Then the is-avail argument is checked. |
| 40 |
* Integrating the TCL interpreter has exposed some interesting bugs |
| 41 |
** Namely changes to the environment inside tcl2lua.tcl now show up inside Lmod |
| 42 |
** This caused a problem with pushenv when used inside a TCL modulefile |
| 43 |
Now all setenv and pushenv changes inside tcl2lua.tcl are undone on exit |
| 44 |
** Uncaught errors and exits now terminate Lmod not just tcl2lua.tcl |
| 45 |
* TCL break is now supported. |
| 46 |
* setenv and pushenv change the current environment |
| 47 |
** This is so that modulefiles can set an env. var and check it later in the same modulefile |
| 48 |
* My understanding of TCL is not great (re-word!) So I initially relied on a version of the pure TCL implementation of Tmod |
| 49 |
** I converted the setenv prepend-path etc procs to generate lua commands |
| 50 |
|
| 51 |
* TCL support a sandbox to limit what function/command that can be called inside a modulefile |
| 52 |
it is its own thing. It is a TCL sandbox. It is independent of the sandbox that Lmod implements. |
| 53 |
It is why Lmod implements a Lua sandbox. |
| 54 |
* It also allows mapping standard commands to ones under my control. |
| 55 |
** For example the TCL puts command now called myPuts. |
| 56 |
* Translating TCL module help into Lmod help function requires the myPuts hack |
| 57 |
if { $g_help && [info procs "ModulesHelp"] == "ModulesHelp" } { |
| 58 |
set start "help(\[===\[" |
| 59 |
set end "\]===\])" |
| 60 |
setPutMode "inHelp" |
| 61 |
myPuts stdout $start |
| 62 |
catch { ModulesHelp } errMsg |
| 63 |
myPuts stdout $end |
| 64 |
setPutMode "normal" |
| 65 |
} |
| 66 |
* myPuts like all commands: setenv prepend-path etc write to an internal array (g_outputA) |
| 67 |
So there is no output of any kind until the evaluation of the module |
| 68 |
is completed. |
| 69 |
** stderr -> LmodMsgRaw() |
| 70 |
** puts stdout "text msg" -> execute{cmd=[===[$text_msg]===], modeA={}} |
| 71 |
** puts prestdout "text msg" -> io.stdout:write([===[$text_msg]===]) |