Calling a function that has to be later in the code

I’m running into an issue with a tableview that I’m using to make a calculator for a medical protocol.

Basically, the problem seems to be, the function that I need to call needs to be put lower in the code than where it is being called.  Here’s a sample of what I mean:

1 - Loading the data to be used in the tableview

2 - Adding the tableview / onrender / on touch, etc.

3 - Adding the rows to the tableview based on the data from #1

Seems straightforward BUT… I need to call reload the data when they select a row - basically, depending on what they select, it loads certain sections BUT… in order to access the tableview, I need to be below section 2 but called from section 2 (the on touch).

How can I call a routine that is in section 3 from section 2?

Is there anyway to do that?

Thanks!

There are several ways.

Forward declaration:

local foo local bar = function() foo() end foo = function() print("hi") end

Store your functions in a table:

local something = {} function something:bar() self:foo() end function something:foo() print("hi") end

Thanks!  That’ll do the trick!

There are several ways.

Forward declaration:

local foo local bar = function() foo() end foo = function() print("hi") end

Store your functions in a table:

local something = {} function something:bar() self:foo() end function something:foo() print("hi") end

Thanks!  That’ll do the trick!