What are the differences between doFile and require in Lua, especially in Torch? When do you call one but not the other? When will one work but the other won't? (I'm using Lua 5.1, torch7).
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
dofile
loads and executes a file right then and there.
require
is more complicated; it keeps a table of modules that have already been loaded and their return results, to ensure that the same code isn't loaded twice. It also keeps a list of module loaders that handle loading a module, one of which that can load from dll
/so
files.
You probably want require
, as if you're just loading functions, you don't want to duplicate them.