在lua中回调函数也用的比较多,而且比c++的回调函数更加方便,因为不需要定义函数指针。
示例如下:
local m = {}
local list = {name="hello",age=12}
m.call_back_fun_print = function(printID)
print(printID .. "-->" .. list[printID])
end
m.add_list = function(key,value,call_back_fun)
key = tostring(key)
list[key] = value
call_back_fun(key)
end
m.add_list("address","beijing",m.call_back_fun_print) --address-->beijing
return m
参考资料: