How to use a lua script for an entity behaviour?

I want to have enemy behaviour defined in a set of scripts. So, for example, I could have one script for a behaviour that follows the player around or another one for a behaviour that runs away from the player.

I’ve looked into the lua examples HelloLua and TestLua, but they don’t help much since they showcase how a game can work entirely from scripts. I want my game to be mostly C++ based, but calling scripts in specific situations.

How would I go about solving this issue for entity behaviour? I think I would need to call a script and pass a reference to the entity to it. Is that possible?

I think you should use lua_pcall or lua_call function in c++ code.