Add indentation aware output functions for exporters

This commit is contained in:
Jason Perkins 2014-01-24 18:57:00 -05:00
parent 17a6308140
commit 623b35aba8
2 changed files with 46 additions and 0 deletions

View File

@ -9,6 +9,8 @@
local config = premake.config local config = premake.config
premake.indentation = 0
--- ---
-- Call the io.esc() value escaping function a value, or a list -- Call the io.esc() value escaping function a value, or a list
@ -64,12 +66,39 @@
error(err, 0) error(err, 0)
end end
premake.indentation = 0
io.output(f) io.output(f)
callback(obj) callback(obj)
f:close() f:close()
end end
---
-- Write a formatted string to the exported file, after decreasing the
-- indentation level by one.
---
function premake.pop(...)
premake.indentation = premake.indentation - 1
premake.w(...)
end
---
-- Write a formatted string to the exported file, and increase the
-- indentation level by one.
---
function premake.push(...)
premake.w(...)
premake.indentation = premake.indentation + 1
end
-- --
-- Wrap the provided value in double quotes if it contains spaces, or -- Wrap the provided value in double quotes if it contains spaces, or
-- if it contains a shell variable of the form $(...). -- if it contains a shell variable of the form $(...).
@ -219,3 +248,19 @@
end end
end end
---
-- Write a formatted string to the exported file (the indentation
-- level is not changed). This gets called quite a lot, hence the
-- very short name.
---
function premake.w(...)
if select("#",...) > 0 then
_p(premake.indentation, ...)
else
_p('')
end
end

View File

@ -285,6 +285,7 @@
premake.solution.list = { } premake.solution.list = { }
premake.api.reset() premake.api.reset()
premake.clearWarnings() premake.clearWarnings()
premake.indentation = 0
io.indent = nil io.indent = nil
io.eol = "\n" io.eol = "\n"