饥荒代码测试
//在线lua代码编写运行 https://wiki.luatos.com/_static/luatos-emulator/lua.html
local print_loggers = {}
local function print_1(...)
print('1\n')
end
local function print_2(...)
print('2\n')
end
local function print_3(...)
print('3\n')
end
table.insert(print_loggers, print_1)
table.insert(print_loggers, print_2)
table.insert(print_loggers, print_3)
for i,v in ipairs(print_loggers) do
v('1')
end
print_loggers[2]() 直接调用print_2 lua语言下标从1开始
无限递归了,不行
local print_loggers = {}
print('123')
function AddPrintLogger( fn )
table.insert(print_loggers, fn)
end
local consolelog = function(...)
print(...)
end
print = function(...)
for i,v in ipairs(print_loggers) do
v(str)
end
end
AddPrintLogger(consolelog)
print('213')