#ifndef _library__lua_function__hpp__included__ #define _library__lua_function__hpp__included__ #include "lua-base.hpp" #include "lua-pin.hpp" namespace lua { /** * Group of functions. */ class function_group { public: /** * Create a group. */ function_group(); /** * Destroy a group. */ ~function_group(); /** * Add a function to group. */ void do_register(const std::string& name, function& fun); /** * Drop a function from group. */ void do_unregister(const std::string& name); /** * Request callbacks on all currently registered functions. */ void request_callback(std::function cb); /** * Bind a callback. * * Callbacks for all registered functions are immediately called. */ int add_callback(std::function cb, std::function dcb); /** * Unbind a calback. */ void drop_callback(int handle); private: int next_handle; std::map functions; std::map> callbacks; std::map> dcallbacks; }; /** * Function implemented in C++ exported to Lua. */ class function { public: /** * Register function. */ function(function_group& group, const std::string& name) throw(std::bad_alloc); /** * Unregister function. */ virtual ~function() throw(); /** * Invoke function. */ virtual int invoke(state& L) = 0; protected: std::string fname; function_group& group; }; } #endif