To set the environment prior to the execution of lua, invoke:
eval `luaenv`
This command is *only* to be used to prepare the environment to execute Lua scripts when calling the lua interpreter not thru ~edrc/bin/lua.
When writing Lua scripts for WA2L/edrc, do *not* use luaenv, start the script thru the .lua_wrapper. See lua_wrapper(1) for information about integrating a Lua script into WA2L/edrc.
When writing recovery scripts in Lua, use the:
#!/usr/bin/env lua
setting in the script magic key and the environment is set correctly.
The GLIBC version <GLIBC> can be resolved using the glibc.version(3), the ldd --version or the getconf GNU_LIBC_VERSION command.
The directory is pre-pended to $LUA_PATH.
The directory is pre-pended to the $LUA_CPATH.
The logic of the libraries is identical to the os_wrapper(1) to support operating systems having different versions of the glibc library.
The GLIBC version <GLIBC> can be resolved using the glibc.version(3), the ldd --version or the getconf GNU_LIBC_VERSION command.
To start a Lua script that uses a bundled Lua module from a recovery script, just call the lua interpreter.
Recovery script:
#!/bin/ksh # # 1:ascript - A Recovery Script calling a Lua script # # [00] 08.02.2009 CWa Initial Version # # test "$DEBUG" = True && set -x : : lua ./luascript :
Lua script:
-- -- luascript - Lua script using bundled lcomplex module -- -- [00] 18.03.2009 CWa Initial Version -- : : local complex = require "complex" :
Write the recovery script in Lua.
Lua recovery script:
#!/usr/bin/env lua -- -- 1:ascript - A Recovery Script in Lua -- -- [00] 08.02.2009 CWa Initial Version -- : : local complex = require "complex" :
Note the use of '#!/usr/bin/env lua' in the magic key to start the Lua script. This ensures that the lua interpreter is found independent of the installation base directory of WA2L/edrc.
The startup method uses the lua interpreter start thru ~edrc/bin/lua that automatically enables to use all Lua packages/modules bundled with WA2L/edrc.
This method is similar to the use of the .lua_wrapper, but the Lua script can be placed somewhere of your liking outside of WA2L/edrc.
Set the permissions of the script to executable:
chmod +x luascript
Lua script:
#!/bin/ksh # # luascript - Lua script using bundled modules # # [00] 18.03.2009 CWa Initial Version # sed '1,/^exit \$\?/d' $0 | ~edrc/bin/lua - "$0" "$@" exit $? -- Lua -- : : local complex = require "complex" :
The startup method method below allows to start the lua interpreter from a specific installation directory on the system and also enables to use all Lua packages/modules bundled with WA2L/edrc using the luaenv command to dynamically initialize the environment.
This method is similar to the use of the .lua_wrapper, but the Lua script can be placed somewhere of your liking outside of WA2L/edrc.
Set the permissions of the script to executable:
chmod +x luascript
Lua script:
#!/bin/ksh # # luascript - Lua script using bundled modules # # [00] 18.03.2009 CWa Initial Version # eval `~edrc/lib/luaenv` sed '1,/^exit \$\?/d' $0 | /usr/bin/lua - "$0" "$@" exit $? -- Lua -- : : local complex = require "complex" :
Try to access the Lua module:
[ / ] [ root@acme007 ][*edrc*/bash]: ~edrc/bin/lua -e 'require "complex"'
If an error message like
/opt/edrc/bin/Linux-64/2.27/lua: (command line):1: module 'complex' not found: no field package.preload['complex'] no file '/opt/edrc/lib/lua/lum/Linux-64/5.4/share/lua/5.4/complex.lua' no file '/usr/local/share/lua/5.4/complex.lua' no file '/usr/local/share/lua/5.4/complex/init.lua' no file '/usr/local/lib/lua/5.4/complex.lua' no file '/usr/local/lib/lua/5.4/complex/init.lua' no file './complex.lua' no file './complex/init.lua' no file '/opt/edrc/lib/lua/lum/Linux-64/5.4/lib/complex.so' no file '/usr/local/lib/lua/5.4/complex.so' no file '/usr/local/lib/lua/5.4/loadall.so' no file './complex.so' stack traceback: [C]: in function 'require' (command line):1: in main chunk [C]: in ?
appears, the package/module cannot be found, if the package/module can be found there is no output.
This is free software; see edrc/doc/COPYING for copying conditions. There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.