What are the differences between doFile and requir

2019-07-24 18:03发布

问题:

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.



标签: lua torch