What are the differences between doFile and requir

2019-07-24 18:30发布

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).

标签: lua torch
1条回答
孤傲高冷的网名
2楼-- · 2019-07-24 18:57

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.

查看更多
登录 后发表回答