luaenv

Package: WA2L/edrc 1.5.57
Section: Library Commands (3)
Updated: 02 May 2025
Index Return to Main Contents

 

NAME

luaenv - print environment needed to start Lua scripts

 

SYNOPSIS

edrc/lib/luaenv [ -n ]

 

AVAILABILITY

WA2L/edrc

 

DESCRIPTION

print the environment used by luaenv to access the Lua packages/modules bundled with WA2L/edrc.

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.

 

OPTIONS

-n
no export VARIABLE ... output.

 

ENVIRONMENT

$LUA_PATH
this variable holds Lua package/module locations additional to the standard applying to an installation. This variable will be expanded with the bundled Lua module locations (lib/lua/lum/<OSID>/<major>.<minor>/share/lua/<major>.<minor>/?.lua;;) when executing the luaenv command.

$LUA_CPATH
path of the Lua package/module libs for the related operating system id and Lua version (lib/lua/lum/<OSID>/<major>.<minor>/lib/lua/<major>.<minor>/[<GLIBC>/]?.so;;) bundled with WA2L/edrc.

The GLIBC version <GLIBC> can be resolved using the glibc.version(3), the ldd --version or the getconf GNU_LIBC_VERSION command.

$PATH
command search path. This variable will be expanded with the path where the lua interpreter was found on the system when executing the luaenv command. See also lua_wrapper(1) for more information.

 

EXIT STATUS

0
always

 

FILES

The <major> is the major version number (e.g. 5) and <minor> is the minor Lua version (e.g. 4).

etc/lua_wrapper.cfg
configuration file for .lua_wrapper and luaenv.

lib/lua/lum/<OSID>/<major>.<minor>/
location of all bundled Lua packages/modules.

lib/lua/lum/<OSID>/<major>.<minor>/share/lua/<major>.<minor>/
Pure Lua modules (.lua files).

The directory is pre-pended to $LUA_PATH.

lib/lua/lum/<OSID>/<major>.<minor>/lib/lua/<major>.<minor>/[<GLIBC>/]
Compiled Lua modules (.so files).

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.

lib/lua/lum/<OSID>/<major>.<minor>/bin/
Scripts provided by some Lua modules.

 

EXAMPLES

1) Start a Lua script from a recovery script

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"
  :

2) Write a recovery script in Lua

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.

3) Write a Lua script outside of WA2L/edrc and profit from bundled Lua modules

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" 
  :

4) Write a Lua script outside of WA2L/edrc and profit from bundled Lua modules

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" 
  :

5) Test the availability of a specific Lua package/module

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.

 

SEE ALSO

edrcintro(1), glibc.version(3), ldd(1), lua(1), luarocks(1), luaversion(3), lua_wrapper(1), osid(3), pkgdir(1m), https://luarocks.org/, https://github.com/luarocks/luarocks/blob/main/docs/index.md

 

NOTES

because the lua executable is bundled with WA2L/edrc the use of luaenv is not so extensively needed as perlenv(3) for Perl scripts or pythonenv(3) for Python scripts.

 

BUGS

-

 

AUTHOR

luaenv was developed by Christian Walther. Send suggestions and bug reports to wa2l@users.sourceforge.net . 

 

COPYRIGHT

Copyright © 2025 Christian Walther

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.


 

Index

NAME
SYNOPSIS
AVAILABILITY
DESCRIPTION
OPTIONS
ENVIRONMENT
EXIT STATUS
FILES
EXAMPLES
SEE ALSO
NOTES
BUGS
AUTHOR
COPYRIGHT

This document was created by man2html using the manual pages.
Time: 18:25:06 GMT, May 02, 2025