1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 <2019> 2020 2021 2022 2023 2024 | Index | 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 <2019> 2020 2021 2022 2023 2024 |
<== Date ==> | <== Thread ==> |
---|
Subject: | Re: EPICS Lua global variables |
From: | "Lang, Keenan C. via Tech-talk" <[email protected]> |
To: | "[email protected]" <[email protected]>, James King - UKRI STFC <[email protected]> |
Date: | Wed, 16 Oct 2019 18:29:11 +0000 |
>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.
From: Tech-talk <[email protected]> on behalf of James King - UKRI STFC via Tech-talk <[email protected]>
Sent: Wednesday, October 16, 2019 11:34 AM To: [email protected] <[email protected]> Subject: EPICS Lua global variables 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
|