在Lua中doFile和require有什么区别 [英] What are the differences between doFile and require in Lua

查看:78
本文介绍了在Lua中doFile和require有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Lua中,尤其是在Torch中,doFile和require之间有什么区别?您什么时候打给别人,而不打给别人?什么时候可以工作,而另一种不能呢?(我正在使用Lua 5.1,torch7).

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

推荐答案

dofile 随即加载并执行文件.

dofile loads and executes a file right then and there.

require 比较复杂;它保留一个已加载模块及其返回结果的表,以确保同一代码不会被加载两次.它还保留了处理模块加载的模块加载器列表,其中一个模块可以从 dll / so 文件加载.

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.

您可能想要 require ,就好像您只是在加载函数一样,不想复制它们.

You probably want require, as if you're just loading functions, you don't want to duplicate them.

这篇关于在Lua中doFile和require有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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