hoa_script::GameScript Class Reference

Singleton class that manages all open script files. More...

#include <script.h>

Inheritance diagram for hoa_script::GameScript:

Inheritance graph
[legend]
Collaboration diagram for hoa_script::GameScript:

Collaboration graph
[legend]
List of all members.

Public Member Functions

lua_State * GetGlobalState ()
 Returns a pointer to the global lua state.
void HandleCastError (luabind::cast_failed &err)
 Handles casting errors generated by Lua return values.
void HandleLuaError (luabind::error &err)
 Handles run-time errors generated in Lua.
bool IsFileOpen (const std::string &filename)
 Checks if a file is already in use by a ScriptDescriptor object.
bool SingletonInitialize ()
 A method for the inheriting class to implement, which initializes the class.
 ~GameScript ()

Private Member Functions

void _AddOpenFile (ScriptDescriptor *sd)
 Adds an open file to the list of open files.
void _RemoveOpenFile (ScriptDescriptor *sd)
 Removes an open file from the list of open files.
 GameScript ()

Private Attributes

lua_State * _global_state
 The lua state shared globally by all files.
std::map< std::string, ScriptDescriptor * > _open_files
 Maintains a list of all data files that are currently open.

Friends

class hoa_utils::Singleton< GameScript >
class ModifyScriptDescriptor
class ReadScriptDescriptor
class ScriptDescriptor
class WriteScriptDescriptor

Detailed Description

Singleton class that manages all open script files.

****************************************************************************

This class monitors all open script files and their descriptor objects. It maintains a global Lua state that all open Lua files use to communicate with each other and with the C++ engine.

Note:
This class is a singleton

Definition at line 194 of file script.h.


Constructor & Destructor Documentation

hoa_script::GameScript::~GameScript (  ) 

Definition at line 54 of file script.cpp.

References _global_state, _open_files, and hoa_script::SCRIPT_DEBUG.

hoa_script::GameScript::GameScript (  )  [private]

Definition at line 40 of file script.cpp.

References _global_state, and hoa_script::SCRIPT_DEBUG.


Member Function Documentation

void hoa_script::GameScript::_AddOpenFile ( ScriptDescriptor sd  )  [private]

Adds an open file to the list of open files.

Definition at line 87 of file script.cpp.

References hoa_script::ScriptDescriptor::_filename, and _open_files.

Referenced by hoa_script::ModifyScriptDescriptor::OpenFile().

void hoa_script::GameScript::_RemoveOpenFile ( ScriptDescriptor sd  )  [private]

Removes an open file from the list of open files.

Definition at line 94 of file script.cpp.

References hoa_script::ScriptDescriptor::_filename, and _open_files.

Referenced by hoa_script::WriteScriptDescriptor::CloseFile(), hoa_script::ReadScriptDescriptor::CloseFile(), and hoa_script::ModifyScriptDescriptor::CloseFile().

lua_State* hoa_script::GameScript::GetGlobalState (  )  [inline]

Returns a pointer to the global lua state.

Definition at line 206 of file script.h.

References _global_state.

Referenced by hoa_script::ModifyScriptDescriptor::OpenFile().

void hoa_script::GameScript::HandleCastError ( luabind::cast_failed &  err  ) 

Handles casting errors generated by Lua return values.

Parameters:
err A reference to the luabind::cast_failed instance that was thrown
This method handles errors specific to casting failures. These errors occur when the return value of a Lua function that is called can not be converted into a proper C++ type.

Definition at line 80 of file script.cpp.

Referenced by hoa_global::GlobalCharacterGrowth::AcknowledgeGrowth(), and hoa_global::GlobalCharacter::GlobalCharacter().

void hoa_script::GameScript::HandleLuaError ( luabind::error &  err  ) 

Handles run-time errors generated in Lua.

Parameters:
err A reference to the luabind::error instance that was thrown
What this method does is retrieve the Lua error message that has been placed on top of the Lua stack, prints the error message to stderr, and removes it from the stack.

Note:
If this method is called after the luabind::error is caught, there is a chance that the lua_State where the error was generated has become invalid. If this is the case, this method will generate a segmentation fault.

Definition at line 71 of file script.cpp.

Referenced by hoa_global::GlobalCharacterGrowth::AcknowledgeGrowth(), hoa_global::GlobalCharacter::GlobalCharacter(), and hoa_map::private_map::DialogueManager::Update().

bool hoa_script::GameScript::IsFileOpen ( const std::string &  filename  ) 

Checks if a file is already in use by a ScriptDescriptor object.

Parameters:
filename The name of the file to check.
Returns:
True if the filename is registered to a ScriptDescriptor object who has the file opened.

Definition at line 101 of file script.cpp.

References _open_files.

Referenced by hoa_script::ModifyScriptDescriptor::OpenFile().

bool hoa_script::GameScript::SingletonInitialize (  )  [virtual]

A method for the inheriting class to implement, which initializes the class.

Returns:
True if initialization was successful, false if it was not

Implements hoa_utils::Singleton< T >.

Definition at line 64 of file script.cpp.

Referenced by InitializeEngine().


Friends And Related Function Documentation

friend class hoa_utils::Singleton< GameScript > [friend]

Definition at line 195 of file script.h.

friend class ModifyScriptDescriptor [friend]

Definition at line 199 of file script.h.

friend class ReadScriptDescriptor [friend]

Definition at line 197 of file script.h.

friend class ScriptDescriptor [friend]

Definition at line 196 of file script.h.

friend class WriteScriptDescriptor [friend]

Definition at line 198 of file script.h.


Member Data Documentation

lua_State* hoa_script::GameScript::_global_state [private]

The lua state shared globally by all files.

Definition at line 242 of file script.h.

Referenced by GameScript(), GetGlobalState(), and ~GameScript().

std::map<std::string, ScriptDescriptor*> hoa_script::GameScript::_open_files [private]

Maintains a list of all data files that are currently open.

Definition at line 239 of file script.h.

Referenced by _AddOpenFile(), _RemoveOpenFile(), IsFileOpen(), and ~GameScript().


The documentation for this class was generated from the following files:
Generated on Fri Jul 6 23:15:38 2007 for Hero of Allacrost by  doxygen 1.5.1