Closed prjemian closed 2 years ago
The INPA
--> A
field structures look like one of the userCalcs.
Note the docker xxxx IOC (synApps 6.2) already has 20 of these luascript
records (2 sets of 10):
root@zap:/opt/iocxxx# less /opt/synApps/support/lua-R3-0-1/luaApp/Db/luascripts10.db
root@zap:/opt/iocxxx# grep set1 dbl-all.txt
gp:set1:userScriptEnable
gp:set1:EnableUserScripts
gp:set1:DisableUserScripts
gp:Slit1Vset1
gp:Slit1Hset1
gp:set1:userScript0
gp:set1:userScript1
gp:set1:userScript2
gp:set1:userScript3
gp:set1:userScript4
gp:set1:userScript5
gp:set1:userScript6
gp:set1:userScript7
gp:set1:userScript8
gp:set1:userScript9
root@zap:/opt/iocxxx# grep set2 dbl-all.txt
gp:set2:userScriptEnable
gp:set2:EnableUserScripts
gp:set2:DisableUserScripts
gp:set2:userScript0
gp:set2:userScript1
gp:set2:userScript2
gp:set2:userScript3
gp:set2:userScript4
gp:set2:userScript5
gp:set2:userScript6
gp:set2:userScript7
gp:set2:userScript8
gp:set2:userScript9
root@zap:/opt/iocxxx#
root@zap:/opt/iocxxx# grep lua *
common.iocsh:dbLoadRecords("$(LUA)/luaApp/Db/luascripts10.db", "P=$(PREFIX), R=set1:")
common.iocsh:dbLoadRecords("$(LUA)/luaApp/Db/luascripts10.db", "P=$(PREFIX), R=set2:")
envPaths:epicsEnvSet("LUA","/opt/synApps/support/lua-R3-0-1")
settings.iocsh:# search path for lua scripts
Not needed immediately, pushing to next milestone.
Needs example lua script to use for testing and example. @keenanlang Can you provide an example?
Set VAL to the result of A + B
field(CODE, "return A + B")
Set SVAL to the concatenation of AA and BB
field(CODE, "return AA .. BB")
Run the function ‘example’ from the file test.lua with zero parameters.
field(CODE, "@test.lua example")
Run the function ‘example’ from the file test.lua with two parameters, one a number, the other a string.
field(CODE, "@test.lua example(1, ‘foo’)")
Factorial example - might be a good unit test for file test.lua
test.lua
from above example:
-- defines a factorial function
function fact (n)
if n == 0 then
return 1
else
return n * fact(n-1)
end
end
From the luascript
record's documentation:
The
CODE
expression can also be used to reference a file containing the description of at least a single lua function. If theCODE
field starts with the symbol@
followed by the name of said file, the luascript record will search through a list of directories given by the environment variableLUA_SCRIPT_PATH
(default: current directory) for the given file. A space character and then the name of a function defined in the file lets the luascript record know what function to call when the record processes. Optionally, a set of parameters can be provided that the function will be called with each processing by including a comma separated list enclosed by parentheses.
The EPICS lua module has support for the
luascript
record. Build a Device for theluascript
record.synApps
lua