Lua Call Functions

My problem is that I have a function that needs to be called before its link. In other words, the code is as follows:

doStuff()

local function doStuff()  end

and whenever I try to run it, it cannot reference the doStuff () function. My question is: how can I call this function without moving the function above, where is it called? Therefore, I do not want:

local function doStuff() end

doStuff()

as this will cause errors in other parts of my program.

+4
source share
1 answer

function that must be called before its reference

You can not. You need to solve this problem differently. The only situation you may need to do is if you have two functions that call each other recursively. You can do this:

local a
local function b()
  a()
end
a = function()
  b()
end
a()

, . - , ( ).

+4

Source: https://habr.com/ru/post/1570719/


All Articles