lua-users home
lua-l archive

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


> It seems as though this would work to make scripts compatible with
> version 5.2 and preceding versions.  I had thought that making a require
> statement conditional was not supported.
>  
> if _VERSION == "Lua 5.2" then
>     mm = require"mm"
> else
>     require"mm"
> end

That depends entirely on what mm returns if anything. If mm is happy to
set the global mm but not return it then it won't work. I guess it's
safer to do something like this:

local oldrequire=require
function require(x)
	local v=oldrequire(x)
	if _G[x]==nil then _G[x]=v end
	return _G[x]
end