Correct way of communication between objects?

Hi,

This is more of a theoretical question.

So say I have a main.lua file, that contains two objects.

Both of these objects are generated by external modules like that:

local popupGenerator = require "popupGeneragor.lua" local scoreGenerator = require "scoreGeneragor.lua" local popup1 = objectGenerator.new({}) local scoreObject = scoreGenerator.new({})

So I have two things on-screen: a score object that contains and displays score and a popup window.

Additionally, the scoreObject has a function “increse(inputNumber)” that increases its internal score.

The popup1 object contains a background and a button.

The question is, how do I make the button inside the popup1 object call the function that is inside the scoreObject object without making it global?

What I would usually do, would be something like that:

local popupGenerator = require "popupGeneragor.lua" local scoreGenerator = require "scoreGeneragor.lua" local scoreObject = scoreGenerator.new({}) local popup1 = objectGenerator.new({ increaseFunction = function(inputNumber) scoreObject:increase(inputNumber) end })

This way, my popup1 can comfortably call “options.increaseFunction()” inside itself and it works. This solution has always seemed somewhat ‘shabby’ and ‘hardcode’-ish to me… but I might be paranoid. 

Is there an ‘official’ better way of calling functions between objects like that?

tl;dr How to properly call an object’s function from within another object?