Last active
October 31, 2018 18:59
-
-
Save Phrogz/f3716e0666821d1c42c4af0702662db0 to your computer and use it in GitHub Desktop.
Overriding Lua libraries with stub versions, that have access to the originals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- add my custom lib directory to the path | |
package.path = 'lib/?.lua;'..package.path | |
-- add this line only to switch to using the wrappers; | |
-- do this after making any other path adjustments. | |
package.real,package.path = package.path,'debug/?.lua;'..package.path | |
local mylib = require 'mylib' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This is debug/mylib.lua, but Gist won't let me name it that :p | |
-- hide the debug folder from the path temporarily | |
package.orig,package.path = package.path,package.real | |
-- get the real version of the library | |
local mylib = require 'mylib' | |
-- undo the damage we did to the path | |
package.path = package.orig | |
--> make my debug modifications to lib | |
local realfoo = mylib.foo | |
function mylib.foo(...) | |
print("Ha ha, I'm debugging!") | |
local result = realfoo(...) | |
return changeinusefulways(result) | |
end | |
return mylib |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment