source: nrEngine/include/ScriptConnector.h @ 1

Revision 1, 3.3 KB checked in by art, 14 years ago (diff)
Line 
1/***************************************************************************
2 *                                                                         *
3 *   (c) Art Tevs, MPI Informatik Saarbruecken                             *
4 *       mailto: <tevs@mpi-sb.mpg.de>                                      *
5 *                                                                         *
6 *   This program is free software; you can redistribute it and/or modify  *
7 *   it under the terms of the GNU General Public License as published by  *
8 *   the Free Software Foundation; either version 2 of the License, or     *
9 *   (at your option) any later version.                                   *
10 *                                                                         *
11 ***************************************************************************/
12
13
14#ifndef _NR_SCRIPT_CONNECTOR_H_
15#define _NR_SCRIPT_CONNECTOR_H_
16
17//----------------------------------------------------------------------------------
18// Includes
19//----------------------------------------------------------------------------------
20#include "Prerequisities.h"
21#include "EventActor.h"
22#include "ScriptEngine.h"
23
24namespace nrEngine{
25
26
27        //! Script connectors are listening on script engine events and react on them
28        /**
29         * In our engine we do provide some default behaviour of how to access
30         * registered engine's functions in your scripts. However if you implement
31         * a new embedded scripting language you have somehow to bind the calling
32         * of engine's provided function within your script. Only the functions which
33         * are registered in ScriptEngine are for the public use within the engine.
34         *
35         * To connect your scripts with the functions you can ask scripting engine
36         * for registered functions and somehow connect them. The other more elegant
37         * way is to derive a class from this one. If any instance of this class
38         * is created (done automaticaly by the constructors), so the class will act
39         * as a event listener and wait for certain scripting engine events. If they
40         * occurs it will call virtual functions overwriten by your class which handle
41         * this events. In this way you just derive any new class from this one and
42         * write a glue code to connect new functions (coming by events) within your
43         * scripting language.
44         *
45         * \ingroup script
46        **/
47        class _NRExport ScriptConnector : public EventActor{
48                public:
49
50                        /**
51                         * Remove the listener and release used memory
52                         **/
53                        virtual ~ScriptConnector();
54
55                protected:
56
57                        /**
58                         * Call this function to get noticed about all currently
59                         * registered functions
60                         * This function should be called from the constructor of derived class.
61                         **/
62                        void initialize();
63
64                        /**
65                         * Protected constructor, so you can only create instancies
66                         * of this class in derived classes.
67                         * The constructor will add itself as a listener on scripting evnets.
68                         **/
69                        ScriptConnector(const std::string& name);
70
71                        /**
72                         * React on events coming from the scripting engine
73                         **/
74                        void OnEvent(const EventChannel& channel, SharedPtr<Event> event);
75
76                        /**
77                         * New function was registered, so handle it
78                         **/
79                        virtual void OnRegisterFunction(const std::string& name, const ScriptFunctor& func) = 0;
80                       
81                        /**
82                         * A function was removed from the database
83                         **/
84                        virtual void OnRemoveFunction(const std::string& name) = 0;
85
86                       
87        };
88
89
90};
91
92#endif
Note: See TracBrowser for help on using the repository browser.