是否可以修改Lua脚本要求? [英] Is it possible to modify the Lua script to require?

查看:122
本文介绍了是否可以修改Lua脚本要求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Lua中调用require 'name'时,该名称可以是预加载的模块名称,也可以是当前工作目录中存在的文件.

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.

我有以下两个问题:

A.我想知道是否有可能在需要之前预装模块或文件.

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.而且如果是文件,我想修改所需的脚本(通过在现有代码的前面添加/添加一些代码),然后最终需要修改后的脚本.

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.

AB都可能吗?

P.S .:我正在将Lua与C ++一起使用.

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

推荐答案

A和B都可以吗?

Are A and B both possible?

是的,因为您可以编写自己的需要"功能来满足您的需要(包括您描述的所有内容).您还可以查看 package.searchers ,将您的功能注册为搜索者之一可能足以实现您想要的功能.

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.

这篇关于是否可以修改Lua脚本要求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆