实现原理: 通过将LUA中得回调函数存入LUA注册表中来保存LUA函数,然后在需要回调时从LUA注册表中取出LUA函数进行调用 下面是一些预备知识:(学习两个重要的函数) 原汁原味的英文解释的最透彻,翻译的话就会加入自己的理解 LUA_GLOBALSINDEX LUA_ENVIRONINDEX LUA_REGISTRYINDEX Lua provides a registry, a pre-defined table that can be used by any C code to store…
function count( ... ) return function( ... ) i = i+ return i end end local func = count(...) print(func()) print(func()) print(func()) 结果如下: [Finished .1s] lua 闭合函数:一个函数加上该函数所需访问的所有“非局部变量”. 如上所示:count()函数返回了另一个函数,而这个函数使用了count()函数中的局部变量.当该函数被调用时,coun…