lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


The "compat_load" module [1] provides Lua 5.2 compatible `load` and
`loadfile` functions for use in Lua 5.1:

  -- If you wish to avoid dependence on this module in Lua 5.2, do this:
  local CL = pcall(load, '') and _G or require 'compat_load'
  local load     = CL.load
  local loadfile = CL.loadfile

  -- The following now works in both Lua 5.1 and 5.2:
  assert(load('return 2*pi', nil, 't', {pi=math.pi}))()
  assert(loadfile('ex.lua', 't', {print=print}))()

This module might be merged into a more general Lua 5.2 compatibility
library (e.g. a full reimplementation of Lua 5.2 `_G`).  However,
`load/loadfile` perhaps are among the more cumbersome functions not to
have.

For related work see [2].

[1] https://gist.github.com/1654007
[2] http://lua-users.org/wiki/LuaVersionCompatibility