5.1之前, 全局变量存储在_G这个table中, 这样的操作:a = 1 相当于:_G['a'] = 1 但在5.2之后, 引入了_ENV叫做环境,与_G全局变量表产生了一些混淆,需要从原理上做一个理解.在5.2中, 操作a = 1相当于_ENV['a'] = 1这是一个最基础的认知改变,其次要格外注意_ENV不是全局变量,而是一个upvalue(非局部变量). 其次,_ENV['_G']指向了_ENV自身,这一目的是为了兼容5.1之前的版本,因为之前你也许会用到: _G['a'] = 2 ,…