diff options
Diffstat (limited to '3rdparty/genie/src/base/io.lua')
-rw-r--r-- | 3rdparty/genie/src/base/io.lua | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/3rdparty/genie/src/base/io.lua b/3rdparty/genie/src/base/io.lua index f5ee64810ea..9ebc03d07e8 100644 --- a/3rdparty/genie/src/base/io.lua +++ b/3rdparty/genie/src/base/io.lua @@ -4,6 +4,14 @@ -- Copyright (c) 2008-2009 Jason Perkins and the Premake project -- +io.eol = "\n" +io.indent = "\t" +io.indentLevel = 0 + +-- default escaper function +local function _escaper(v) return v end +_esc = _escaper + -- -- Prepare to capture the output from all subsequent calls to io.printf(), @@ -76,6 +84,44 @@ end end +-- +-- Write a formatted string to the exported file, after passing all +-- arguments (except for the first, which is the formatting string) +-- through io.esc(). +-- + + function io.xprintf(msg, ...) + local arg = {...} + for i = 1, #arg do + arg[i] = io.esc(arg[i]) + end + io.printf(msg, unpack(arg)) + end + +-- +-- Handle escaping of strings for various outputs +-- + + function io.esc(value) + if type(value) == "table" then + local result = {} + local n = #value + for i = 1, n do + table.insert(result, io.esc(value[i])) + end + return result + end + + return _esc(value or "") + end + +-- +-- Set a new string escaping function +-- + + function io.escaper(func) + _esc = func or _escaper + end -- -- Because I use io.printf() so often in the generators, create a terse shortcut @@ -83,3 +129,4 @@ -- _p = io.printf + _x = io.xprintf |