94 outfile:write(string.format("%q", keyword), ','); |
94 outfile:write(string.format("%q", keyword), ','); |
95 end |
95 end |
96 outfile:write[[}; function prettify(code) return code:gsub("["..string.char(base_char).."-"..string.char(base_char+#keywords).."]", |
96 outfile:write[[}; function prettify(code) return code:gsub("["..string.char(base_char).."-"..string.char(base_char+#keywords).."]", |
97 function (c) return keywords[c:byte()-base_char]; end) end ]] |
97 function (c) return keywords[c:byte()-base_char]; end) end ]] |
98 |
98 |
99 outfile:write [[return assert(loadstring(prettify]] |
99 outfile:write [[return setfenv(assert(loadstring(prettify]] |
100 outfile:write("[", string.rep("=", maxequals+1), "["); |
100 outfile:write("[", string.rep("=", maxequals+1), "["); |
101 |
101 |
102 -- Write code, substituting tokens as we go |
102 -- Write code, substituting tokens as we go |
103 for k,v in ipairs(llex.tok) do |
103 for k,v in ipairs(llex.tok) do |
104 if v == "TK_KEYWORD" or v == "TK_NAME" or v == "TK_STRING" then |
104 if v == "TK_KEYWORD" or v == "TK_NAME" or v == "TK_STRING" then |
113 end |
113 end |
114 end |
114 end |
115 |
115 |
116 -- Close string/functions |
116 -- Close string/functions |
117 outfile:write("]", string.rep("=", maxequals+1), "]"); |
117 outfile:write("]", string.rep("=", maxequals+1), "]"); |
118 outfile:write(", '@", outfile_fn,"'))()"); |
118 outfile:write(", '@", outfile_fn,"')), getfenv())()"); |
119 outfile:close(); |
119 outfile:close(); |
120 os.rename(outfile_fn..".uglified", outfile_fn); |
120 os.rename(outfile_fn..".uglified", outfile_fn); |
121 end |
121 end |
122 |
122 |
123 if opts.uglify then |
123 if opts.uglify then |