Is it possible to modify the Lua script to require?

回眸只為那壹抹淺笑 提交于 2020-01-14 13:45:09

问题


When I call require 'name' in Lua, the name can be either a preloaded module name or a file that exists in a current working directory.

I have the following two questions:

A. I would like to know if it's possible to find out whether a preloaded module or a file will be required right before it will be required.

B. And if it's a file, I want to modify the script which will be required (by prepending/appending some code on top of existing one) and then require the modified script finally.

Are A and B both possible?

P.S.: I'm using Lua with C++.


回答1:


Are A and B both possible?

Yes, as you can write your own "require" function that does what you need (including everything you describe). You can also look at package.searchers, as registering your function as one of the searchers may be enough to implement what you want.



来源:https://stackoverflow.com/questions/51701228/is-it-possible-to-modify-the-lua-script-to-require

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!