lua - Lua 中的函数定义

标签 lua

有什么区别吗

local splitPathFileExtension = function (res)
end

function splitPathFileExtension(res)
end

?我知道在第一种情况下这个函数是匿名的,但这是唯一的区别?

最佳答案

它们几乎完全相同(除了您将第一个函数指定为 local 而不是第二个函数。)

参见 manual关于函数定义:

The statement

    function f () body end

corresponds to

    f = function () body end

The statement

    function t.a.b.c.f () body end

translates to

    t.a.b.c.f = function () body end

The statement

    local function f () body end

translates to

    local f; f = function () body end

not to

    local f = function () body end

(This only makes a difference when the body of the function contains references to f.)

关于lua - Lua 中的函数定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31604850/

相关文章:

performance - 使用表来提高CPU使用率有好处吗?

windows - 如何在 luasocket 3 中使用 Lua 5.2

c++ - 如何使 SWIG 绑定(bind)类在 Lua 中使用运算符?

c - 检测lua表爬行中的无限循环

multithreading - 协程的好处是什么?

lua - 如何解决这个解包问题?

android - 在 Corona 小部件中显示在模拟器中但不在设备上

c - luajit ffi构造函数参数路由

Lua 表和迭代

lua - Tarantool 中的冲突解决(如何在发生冲突时修复主-主模式下的复制)