1 |
1 |
2 -- Not entirely sure that this is correct |
2 local cs = require "minichunkspy" |
3 -- (produces files twice the size of luac) |
|
4 -- but it appears to work... |
|
5 |
3 |
6 function compile_string(str, name) |
4 function compile_string(str, name) |
7 -- Strips debug info, if you're wondering :) |
5 -- Strips debug info, if you're wondering :) |
8 local b=string.dump(assert(loadstring(str,name))) |
6 local chunk = string.dump(loadstring(str, name)); |
9 local x,y=string.find(b,str.."\0") |
7 if ((not opts.debug) or opts.compile_strip) and opts.compile_strip ~= false then |
10 if not (x and y) then return b; end -- No debug info sometimes? |
8 local c = cs.disassemble(chunk); |
11 return string.sub(b,1,x-5).."\0\0\0\0"..string.sub(b, y+1, -1) |
9 local function strip_debug(c) |
|
10 c.source_lines, c.locals, c.upvalues = {}, {}, {}; |
|
11 |
|
12 for i, f in ipairs(c.prototypes) do |
|
13 strip_debug(f); |
|
14 end |
|
15 end |
|
16 print_verbose("Stripping debug info..."); |
|
17 strip_debug(c.body); |
|
18 return cs.assemble(c); |
|
19 end |
|
20 return chunk; |
12 end |
21 end |
13 |
22 |
14 function compile_file(infile_fn, outfile_fn) |
23 function compile_file(infile_fn, outfile_fn) |
15 local infile, err = io.open(infile_fn); |
24 local infile, err = io.open(infile_fn); |
16 if not infile then |
25 if not infile then |