residualvm/residualvm-tools — pull request #24 by YakBizzarro (2012-04-16 13:49:09+00:00)
Title: LUAC: Add rebase function

Patching lua scripts used to be difficult, since recomplied modified scripts have a very different bytecode. This commit adds a way to recompile them, with a bytecode as close as possible to the original. This is achieved by:
-Using the same filename and the functions line numbers specified in the original one
-Rebuilding the constant list to have the most similar order compared to the original
An example of use:
luac -o output.LUA -b original_unlabbed_script.LUA source_of_modified_script.lua

Please note that this method doesn't work with _system.LUA, because this script has the debugging symbols mixed with the code and we can't simply ignore them.

The scripts built with this method, could be diffed with diffr, a tool from future version of patchr (i'm still working on it, a very rough draft of it could be found on https://github.com/YakBizzarro/residual-tools/commit/edd0ce0db0062c6101561b2c050b66cf676296dc and https://github.com/YakBizzarro/residual/commit/1f23a257a72889f03a2062575f1a0e80e0ceda63 )