Code Monkey home page Code Monkey logo

cpp-callback-script's Introduction

Overview

cpp-callback-script is a sample C++ application that is extended by a Lua script.

Dependencies

To run the sample, you need to have the following libraries installed:

Structure

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.

Environment

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.

EnvironmentClient

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:

  • callbackRespondsToKey returns a list keys this particular EnvironmentClient instance responds to
  • callbackCall returns 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.

C++ side

runCPP function inside main.cpp registers two EnvironmentClient instances that respond to different keys.

Lua side

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.

cpp-callback-script's People

Contributors

kornerr avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.