Module pl.compat

Lua 5.1/5.2/5.3 compatibility.

Ensures that table.pack and package.searchpath are available for Lua 5.1 and LuaJIT. The exported function load is Lua 5.2 compatible. compat.setfenv and compat.getfenv are available for Lua 5.2, although they are not always guaranteed to work.

Functions

execute (cmd) execute a shell command.
load (ld[, source[, mode[, env]]]) Load Lua code as a text or binary chunk.
getfenv (f) Get environment of a function.
setfenv (f, env) Set environment of a function

Lua 5.2 Functions Available for 5.1

table.pack (...) pack an argument list into a table.
package.searchpath (mod, path) return the full path where a Lua module name would be matched.


Functions

execute (cmd)
execute a shell command. This is a compatibility function that returns the same for Lua 5.1 and Lua 5.2

Parameters:

  • cmd a shell command

Returns:

  1. true if successful
  2. actual return code
load (ld[, source[, mode[, env]]])
Load Lua code as a text or binary chunk.

Parameters:

  • ld code string or loader
  • source name of chunk for errors (optional)
  • mode ‘b’, ’t' or ‘bt’ (optional)
  • env environment to load the chunk in (optional)
getfenv (f)
Get environment of a function. With Lua 5.2, may return nil for a function with no global references! Based on code by Sergey Rozhenko

Parameters:

  • f a function or a call stack reference
setfenv (f, env)
Set environment of a function

Parameters:

  • f a function or a call stack reference
  • env a table that becomes the new environment of f

Lua 5.2 Functions Available for 5.1

table.pack (...)
pack an argument list into a table.

Parameters:

  • ... any arguments

Returns:

  1. a table with field n set to the length
  2. the length
package.searchpath (mod, path)
return the full path where a Lua module name would be matched.

Parameters:

  • mod module name, possibly dotted
  • path a path in the same form as package.path or package.cpath

See also:

generated by LDoc 1.4.6 Last updated 2017-07-18 16:28:41