Sun, 26 Jul 2009 03:59:35 +0100
Add support for virtual IO in dofile and loadfile
squish.lua | file | annotate | diff | comparison | revisions |
--- a/squish.lua Sun Jul 26 03:38:20 2009 +0100 +++ b/squish.lua Sun Jul 26 03:59:35 2009 +0100 @@ -212,7 +212,21 @@ return io_lines(fn); else return vio.open(resources[fn]):lines() - end end ]] + end end + local _dofile = dofile; + function dofile(fn) + if not resources[fn] then + return _dofile(fn); + else + return assert(loadstring(resources[fn]))(); + end end + local _loadfile = loadfile; + function loadfile(fn) + if not resources[fn] then + return _loadfile(fn); + else + return loadstring(resources[fn], "@"..fn); + end end ]] end end f:write[[function require_resource(name) return resources[name] or error("resource '"..tostring(name).."' not found"); end end ]]