Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Module 扩展标准库模块_Module_Lua - Fatal编程技术网

Module 扩展标准库模块

Module 扩展标准库模块,module,lua,Module,Lua,是否可以扩展(甚至覆盖)标准库模块。我希望能做一些类似的事情 -- eggs.lua table.spam = function(tab) return tab[1] end 然后 -- ham.lua require('eggs') table.spam({2,7,1,3}) 是的,这是可能的,尽管建议不要修改标准库名称空间,而是使用tablex作为。实际上,返回匿名或本地表更可取,因为这样您可以在需要时选择名称:local tablex=require'egs'。当使用\u索引元

是否可以扩展(甚至覆盖)标准库模块。我希望能做一些类似的事情

-- eggs.lua
table.spam = function(tab)
    return tab[1]
end
然后

-- ham.lua
require('eggs')
table.spam({2,7,1,3})

是的,这是可能的,尽管建议不要修改标准库名称空间,而是使用
tablex
作为。

实际上,返回匿名或本地表更可取,因为这样您可以在需要时选择名称:
local tablex=require'egs'
。当使用
\u索引
元表时,您甚至可以通过任何未知(=unwrapped)调用传递到