Crazy Eddie's GUI System 0.8.7
Loading...
Searching...
No Matches
ScriptModules/Lua/ScriptModule.h
1/***********************************************************************
2 created: 16/3/2005
3 author: Tomas Lindquist Olsen
4
5 purpose: Defines interface for LuaScriptModule class
6*************************************************************************/
7/***************************************************************************
8 * Copyright (C) 2004 - 2008 Paul D Turner & The CEGUI Development Team
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * a copy of this software and associated documentation files (the
12 * "Software"), to deal in the Software without restriction, including
13 * without limitation the rights to use, copy, modify, merge, publish,
14 * distribute, sublicense, and/or sell copies of the Software, and to
15 * permit persons to whom the Software is furnished to do so, subject to
16 * the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
28 ***************************************************************************/
29#ifndef _CEGUILua_h_
30#define _CEGUILua_h_
31
32
33/*************************************************************************
34 Import / Export control macros
35*************************************************************************/
36#if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
37# ifdef CEGUILUASCRIPTMODULE_EXPORTS
38# define CEGUILUA_API __declspec(dllexport)
39# else
40# define CEGUILUA_API __declspec(dllimport)
41# endif
42#else
43# define CEGUILUA_API
44#endif
45
46
47#include "CEGUI/ScriptModule.h"
48
49struct lua_State;
50
51// Start of CEGUI namespace section
52namespace CEGUI
53{
54
59class CEGUILUA_API LuaScriptModule : public CEGUI::ScriptModule
60{
61public:
62 /*************************************************************************
63 Construction and Destruction
64 *************************************************************************/
73 static LuaScriptModule& create(lua_State* state = 0);
74
76 static void destroy(LuaScriptModule& mod);
77
78
79 /*************************************************************************
80 Script Execution Functions
81 *************************************************************************/
94 void executeScriptFile(const String& filename, const String& resourceGroup);
95
113 void executeScriptFile(const String& filename,
114 const String& resourceGroup,
115 const String& error_handler);
116
134 void executeScriptFile(const String& filename,
135 const String& resourceGroup,
136 const int error_handler);
137
150 int executeScriptGlobal(const String& function_name);
151
169 int executeScriptGlobal(const String& function_name,
170 const String& error_handler);
171
189 int executeScriptGlobal(const String& function_name,
190 const int error_handler);
191
192
211 bool executeScriptedEventHandler(const String& handler_name,
212 const EventArgs& e);
213
237 bool executeScriptedEventHandler(const String& handler_name,
238 const EventArgs& e,
239 const String& error_handler);
240
264 bool executeScriptedEventHandler(const String& handler_name,
265 const EventArgs& e,
266 const int error_handler);
267
278 void executeString(const String& str);
279
295 void executeString(const String& str, const String& error_handler);
296
312 void executeString(const String& str, const int error_handler);
313
314 /*************************************************************************
315 Event subscription
316 *************************************************************************/
336 const String& subscriber_name);
337
362 const String& subscriber_name,
363 const String& error_handler);
364
389 const String& subscriber_name,
390 const int error_handler);
391
415 Event::Group group,
416 const String& subscriber_name);
417
446 Event::Group group,
447 const String& subscriber_name,
448 const String& error_handler);
449
478 Event::Group group,
479 const String& subscriber_name,
480 const int error_handler);
481
482 /*************************************************************************
483 Bindings creation / destruction
484 *************************************************************************/
495 void createBindings(void);
496
507 void destroyBindings(void);
508
509 /*************************************************************************
510 Accessor type functions
511 *************************************************************************/
520 lua_State* getLuaState(void) const {return d_state;}
521
522 /*************************************************************************
523 Lua error handler related functions
524 *************************************************************************/
535 void setDefaultPCallErrorHandler(const String& error_handler_function);
536
546 void setDefaultPCallErrorHandler(int function_reference);
547
563
587
588private:
589 /*************************************************************************
590 Implementation Functions
591 *************************************************************************/
600 LuaScriptModule(lua_State* state);
601
604
605
606 void setModuleIdentifierString();
611 int initErrorHandlerFunc();
616 int initErrorHandlerFunc(const String func_name);
621 int initErrorHandlerFunc(int func);
622
628 void cleanupErrorHandlerFunc();
629
631 void unrefErrorFunc();
632
634 void executeScriptFile_impl(const String& filename,
635 const String& resourceGroup,
636 const int err_idx, const int top);
637
639 int executeScriptGlobal_impl(const String& function_name,
640 const int err_idx, const int top);
641
643 bool executeScriptedEventHandler_impl(const String& handler_name,
644 const EventArgs& e,
645 const int err_idx, const int top);
646
648 void executeString_impl(const String& str, const int err_idx, const int top);
649
650 /*************************************************************************
651 Implementation Data
652 *************************************************************************/
654 bool d_ownsState;
656 lua_State* d_state;
658 String d_errFuncName;
660 int d_errFuncIndex;
664 String d_activeErrFuncName;
668 int d_activeErrFuncIndex;
669};
670
671} // namespace CEGUI
672
673#endif // end of guard _CEGUILua_h_
Base class used as the argument to all subscribers Event object.
Definition EventArgs.h:51
Interface providing event signaling and handling.
Definition EventSet.h:167
unsigned int Group
Type for a subscriber group. You can use the subscriber group to order calls to multiple subscribers....
Definition Event.h:84
Interface for the LuaScriptModule class.
Definition ScriptModules/Lua/ScriptModule.h:60
void executeScriptFile(const String &filename, const String &resourceGroup)
Execute a script file.
bool executeScriptedEventHandler(const String &handler_name, const EventArgs &e)
Execute a scripted global 'event handler' function by looking it up by name.
void executeScriptFile(const String &filename, const String &resourceGroup, const int error_handler)
Execute a script file.
lua_State * getLuaState(void) const
Method used to get a pointer to the lua_State that the script module is attached to.
Definition ScriptModules/Lua/ScriptModule.h:520
bool executeScriptedEventHandler(const String &handler_name, const EventArgs &e, const String &error_handler)
Execute a scripted global 'event handler' function by looking it up by name.
void executeString(const String &str, const String &error_handler)
Execute script code contained in the given CEGUI::String object.
Event::Connection subscribeEvent(EventSet *target, const String &name, Event::Group group, const String &subscriber_name)
Subscribes the specified group of the named Event to a scripted funtion.
const String & getActivePCallErrorHandlerString() const
Return the function name string of the active error handler function.
Event::Connection subscribeEvent(EventSet *target, const String &name, Event::Group group, const String &subscriber_name, const int error_handler)
Subscribes the specified group of the named Event to a scripted funtion.
void setDefaultPCallErrorHandler(int function_reference)
Set the function that will be passed as the error handler in calls to lua_pcall, unless an alternativ...
void executeString(const String &str)
Execute script code contained in the given CEGUI::String object.
int getActivePCallErrorHandlerReference() const
return the lua registry index of the active error handler function.
int executeScriptGlobal(const String &function_name, const int error_handler)
Execute a scripted global function. The function should not take any parameters and should return an ...
Event::Connection subscribeEvent(EventSet *target, const String &name, const String &subscriber_name, const int error_handler)
Subscribes the named Event to a scripted funtion.
void createBindings(void)
Method called during system initialisation, prior to running any scripts via the ScriptModule,...
static void destroy(LuaScriptModule &mod)
Destroys the given LuaScriptModule object.
void destroyBindings(void)
Method called during system destruction, after all scripts have been run via the ScriptModule,...
int executeScriptGlobal(const String &function_name, const String &error_handler)
Execute a scripted global function. The function should not take any parameters and should return an ...
static LuaScriptModule & create(lua_State *state=0)
Creates a LuaScriptModule object.
void executeScriptFile(const String &filename, const String &resourceGroup, const String &error_handler)
Execute a script file.
bool executeScriptedEventHandler(const String &handler_name, const EventArgs &e, const int error_handler)
Execute a scripted global 'event handler' function by looking it up by name.
Event::Connection subscribeEvent(EventSet *target, const String &name, const String &subscriber_name)
Subscribes the named Event to a scripted funtion.
void executeString(const String &str, const int error_handler)
Execute script code contained in the given CEGUI::String object.
int executeScriptGlobal(const String &function_name)
Execute a scripted global function. The function should not take any parameters and should return an ...
Event::Connection subscribeEvent(EventSet *target, const String &name, const String &subscriber_name, const String &error_handler)
Subscribes the named Event to a scripted funtion.
void setDefaultPCallErrorHandler(const String &error_handler_function)
Set the name of the lua function that will be passed as the error handler in calls to lua_pcall,...
Event::Connection subscribeEvent(EventSet *target, const String &name, Event::Group group, const String &subscriber_name, const String &error_handler)
Subscribes the specified group of the named Event to a scripted funtion.
Abstract interface required for all scripting support modules to be used with the CEGUI system.
Definition ScriptModule.h:47
String class used within the GUI system.
Definition String.h:64
Main namespace for Crazy Eddie's GUI Library.
Definition arch_overview.dox:1