>we cannot use local variables as they drop out of scope due to the nature of Lua interactive mode scopes.
Yeah, due to the way the input is analyzed to see if you have a valid code chunk and the need for the code to be turned into opcodes for the interpreter, scopes end up being a bit weird with a shell. If you have a multiline statement (ie functions or conditionals),
local variables can be used and the definition will be confined to that scope. For single-line commands, the scope is the line itself and local variables will disappear by the next line, unfortunately.
>Or any information as to how global variables are contained in the Lua shell?
Global variables stay in scope until the lua shell is exited, they won't be exported into the overarching environment variables unless you use epicsEnvSet. Calling another lua shell within the current one (like using the '<' character to include another file)
only has the effect of changing where input is coming from, so global variables will be shared between the two and the end of the inner context won't cause global variables to expire. One thing to note, though, if you are fully replacing the ioc shell with
the lua shell in your <app>Main.c, there are two calls to the lua shell. One is for if you specify a startup script on the command line, and then another to provide the interactive shell. Since they are two different calls, if you specify global variables
in your st.lua or whatever file, they won't be there once you reach the interactive shell.
Hello Tech-talk,
I have been working on getting an IOC booting with Lua. Lua guidelines suggest the use of local variables rather than global. I notice that Macros are available as global variables and we cannot use local variables as they drop out of
scope due to the nature of Lua interactive mode scopes.
Does anyone have any experience of using local variables in Lua IOC boot scripts? Or any information as to how global variables are contained in the Lua shell?
Many thanks for any replies and help given.
Kind regards,
James
|