would it be possible to check whenever the require inbuild function is called?
Printable View
would it be possible to check whenever the require inbuild function is called?
Just register your own function that calls require
but I want to use the inbuild require aswell :[
Loop through the whole script, searching for 'require', excluding string and comments, and replace it by requireX, then register that function :D
that would be annoying to do with 53 files spread through 7 folders with an unknown number of subfolders
or if you had the requires inside another function, like:
it might even be better to do that if you ever need to reload whatever was used by requireCode:function load()
blah = require("whatever")
signal()
end
the reason I want it to be require is because its recognized by alot of lua editing programs such as Notepad++. I already thought of that, Xgoff, but I figured having the require function as the one would be better.
about the only other thing i can think of, then, is overwriting the standard require with your own function after moving the real require to some other variable
that's pretty crude but it might work, though i don't know if modules will use that one or the default requireCode:require2 = require
require = function (...)
alert_function()
return require2(...)
end
That *might* work, I need to test it out. Hold on.
ilu Xgoff <3 It worked beautifully. Thanks!
Wow, nice. Didn't know that's possible, I'll definitely memorize this!
Your solution should work perfectly fine (it's the preferred way to do it, actually) because 'require' is a global unless imported modules change it themselves.Quote:
Originally Posted by xyzzy
Also, make require2 a local, or usercode will have access to the 'real' require :)
ANOTHER QUESTION
how would I, inside Lua, send the relative path of a file?
Say I have a function called loadImage(path)
how would I load it depending on the script location?
I was thinking something like loadImage("./image.png")
how would I achieve that? :o