Backport to Lua 5.1 (because 5.2 on Travis doesn't have luaposix...).

This commit is contained in:
David Given 2016-08-14 22:52:57 +02:00
parent 38c6a87ed5
commit 53f043ff40
3 changed files with 25 additions and 11 deletions

View file

@ -1,5 +1,5 @@
before_install:
- sudo apt-get install ed lua5.2 lua-posix ninja
- sudo apt-get install ed lua5.1 liblua5.1-posix1 ninja
language: c
script:
- make PREFIX=/tmp/acki -j4

View file

@ -91,7 +91,7 @@ endif
$(BUILDDIR)/rules.ninja: first/ackbuilder.lua $(BUILD_FILES)
@mkdir -p $(BUILDDIR)
@lua5.2 first/ackbuilder.lua first/build.lua build.lua --ninja > $(BUILDDIR)/rules.ninja
@lua5.1 first/ackbuilder.lua first/build.lua build.lua --ninja > $(BUILDDIR)/rules.ninja
$(BUILDDIR)/rules.mk: first/ackbuilder.lua $(BUILD_FILES)
@mkdir -p $(BUILDDIR)

View file

@ -346,10 +346,11 @@ local function templateexpand(list, vars)
o[#o+1] = s:gsub("%%%b{}",
function(expr)
expr = expr:sub(3, -2)
local chunk, e = load("return ("..expr..")", expr, "text", vars)
local chunk, e = loadstring("return ("..expr..")", expr)
if e then
error(string.format("error evaluating expression: %s", e))
end
setfenv(chunk, vars)
local value = chunk()
if (value == nil) then
error(string.format("template expression '%s' expands to nil (probably an undefined variable)", expr))
@ -381,7 +382,10 @@ local function loadbuildfile(filename)
local thisglobals = {}
thisglobals._G = thisglobals
setmetatable(thisglobals, {__index = globals})
chunk, e = load(data, "@"..filename, "text", thisglobals)
chunk, e = loadstring(data, "@"..filename)
if not e then
setfenv(chunk, thisglobals)
end
end
end
if e then
@ -396,6 +400,22 @@ local function loadbuildfile(filename)
loadingstack[#loadingstack] = nil
end
local function loadbuildfilefor(filepart, targetpart)
local normalname = concatpath(filepart, "/build.lua")
if posix.access(normalname, "r") then
loadbuildfile(normalname)
return
end
local extendedname = concatpath(filepart, "/build-"..targetpart..".lua")
if posix.access(extendedname, "r") then
loadbuildfile(extendedname)
return
end
error(string.format("could not access either '%s' or '%s'", normalname, extendedname))
end
loadtarget = function(targetname)
if targets[targetname] then
return targets[targetname]
@ -428,13 +448,7 @@ loadtarget = function(targetname)
if (filepart == "") then
filepart = cwd
end
local filename = concatpath(filepart, "/build.lua")
if posix.access(filename, "r") then
loadbuildfile(filename)
else
filename = concatpath(filepart, "/build-"..targetpart..".lua")
loadbuildfile(filename)
end
loadbuildfilefor(filepart, targetpart)
target = targets[targetname]
if not target then