我有一个函数,它将创建一个函数并在表中插入该函数,它有点像这样。
local Events = {}
Events.Functions = {}
Events.AddEvent = function(code1)
local Event = function(code1)
loadstring(code1)
end
table.insert(Events.Functions, Event)
end
Events.AddEvent("print(\"hello\")")
答案 0 :(得分:2)
loadstring
(或Lua 5.2或更高版本中的load
)本身会返回一个函数,在定义function
时不需要额外的Event
:
local Event = loadstring(code1)
table.insert(Events.Functions, Event)
或者简单地说:
table.insert(Events.Functions, loadstring(code1))