Function names in table fields

lua will correctly resolve the function adresses for printLower and printUpper in the choice.functions table in the example below.

choice  = {
    keys  = {"j", "J", "C-j"},
    functions  = {
  j  = printLower,
  J  = printUpper,
  }
}
function printLower()
  celestia:print("Menu choice = J")
end
function printUpper()
  celestia:print("Menu choice = [Shift]+[J]")
end

lua will however nót resolve those adresses at all if you do the same thing using a little bit different syntax for the definition of the table.

menu.choice  = {}
menu.choice.keys  = {"j", "J"}
menu.choice.functions  = {}
menu.choice.functions["j"]  = printLower
menu.choice.functions["J"]  = printUpper
function printLower()
  celestia:print("Menu choice = J")
end
function printUpper()
  celestia:print("Menu choice = [Shift]+[J]")
end

Although In this example exactly the same happens in exactly the same following order, lua will value the printLower and printUpper fields as nil and you will end up with an error when you try to run the script in Celestia.

The second example is in fact correct, since in general lua can't resolve adresses of fields or functions that it hasn't seen yet and expects a following order as shown below.

function printLower()
  celestia:print("Menu choice = J")
end
function printUpper()
  celestia:print("Menu choice = [Shift]+[J]")
end
menu.choice  = {}
menu.choice.keys  = {"j", "J"}
menu.choice.functions  = {}
menu.choice.functions["j"]  = printLower
menu.choice.functions["J"]  = printUpper