Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lua - want to call a function in main.lua from another module

I want a to call a function that is defined in main.lua from a module that is required (included) in main.lua. What's the best/cleanest way to do this?

Edit:

I eventually went down the dispatch event route. That seems to be a neat way of doing it.

like image 720
camden_kid Avatar asked Sep 21 '26 09:09

camden_kid


1 Answers

There are two options as far as I can see:

  1. Define the function A first, then require() the module, and call function A there.
  2. require() the module first, and have the module define a function B that calls the function A in your main file. Call function B whenever you are ready to call it (i.e. function A is defined) in your main file.

The latter seems cleaner, but that would be a matter of personal preference.

like image 153
Jasmijn Avatar answered Sep 25 '26 10:09

Jasmijn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!