Skip to content

Instantly share code, notes, and snippets.

@Phrogz
Last active October 31, 2018 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Phrogz/f3716e0666821d1c42c4af0702662db0 to your computer and use it in GitHub Desktop.
Save Phrogz/f3716e0666821d1c42c4af0702662db0 to your computer and use it in GitHub Desktop.
Overriding Lua libraries with stub versions, that have access to the originals
-- 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 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