I'm at the point of adding Lua script support in my engine. To override object events (onCollision, onUpdate, onWhatever), trigger events, UI interaction, and so on. About half of these scripts are only called "sometimes", when needed, yet other events may occur relative often, which makes me worrying about the performance a bit.
I did something similar a long time ago with Python, and then chose to collect all code pieces first, dump them in 1 large file, pre-compile it, get all functions from the script and register all my "API" (stuff the script can call from my engine) functions. So the whole pre-compilation and setup only had to be done once.
Grabbing all code from all possible entities, and then (re)naming it to ensure each entity class had its own unique functions was quite a task though. So before going that route again, I wonder if its worth it. Plus I'm new to Lua anyway.
So let's say if we have 100 different entities (monster, shotgun, medkit, door, lightswitch, ...), each with a bunch of functions (onClick, onHit, onUpdate, onXYZ, ...). What would be the best way to deal with these scripts ->
A: Just call & compile the individual functions on the fly when they're needed
B: Give each entity its own script (and to the registering for each script again)
C: Collect all code, make 1 huge file (with a lot functions inside!), register once
D: Something different?
My feeling says B is the clean & comfy way... but maybe not the most efficient way, although if it only means a slight longer initial loading time... I'm fine with that.