Forward define a function in Lua?

前端 未结 6 1279
终归单人心
终归单人心 2020-12-17 09:03

How do I call a function that needs to be called from above its creation? I read something about forward declarations, but Google isn\'t being helpful in this case. What is

6条回答
  •  感动是毒
    2020-12-17 09:47

    Testing under the embedded lua in Freeswitch, forward declaration does not work:

    fmsg("CRIT", "It worked.")
    function fmsg(infotype, msg)
       freeswitch.consoleLog(infotype,  msg .. "\n")
    end
    

    result:

    [ERR] mod_lua.cpp:203 /usr/local/freeswitch/scripts/foo.lua:1: attempt to call global 'fmsg' (a nil value)

    Reversing the order does (duh) work.

提交回复
热议问题