cpp-callback-script is a sample C++ application that is extended by a Lua script.
To run the sample, you need to have the following libraries installed:
The sample application provides an abstraction to separate functionality
into several modules with the help of Environment and EnvironmentClient
classes.
Such a separation allows one to provide parts of the application either as a C++ code, or a Lua one.
The application has Environment that provides a member function
with the following signature:
Strings call(const String &key, const Strings &values).
The function passes a list of string values (std::vector) to the specified
key and returns a result as another list of string values.
The application also has EnvironmentClient that serves as a callback
container for third parties wishing to interact indirectly through Environment.
EnvironmentClient has the following callbacks:
callbackRespondsToKeyreturns a list keys this particularEnvironmentClientinstance responds tocallbackCallreturns a list of keys as a result of running provided callback
The callbacks use std::function to remove the need for third parties
to inherit EnvironmentClient to specify custom behaviour.
runCPP function inside main.cpp registers two EnvironmentClient
instances that respond to different keys.
runSol function inside main.cpp registers Environment,
EnvironmentClient with Lua (using Sol2), and then runs script.lua.
script.lua, in its turn, creates an instance of EnvironmentClient
that responds to a new key.