Crazy Eddies GUI System: CEGUI::LuaScriptModule Class Reference

Crazy Eddies GUI System 0.7.6

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions
CEGUI::LuaScriptModule Class Reference

Interface for the LuaScriptModule class. More...

Inheritance diagram for CEGUI::LuaScriptModule:
[legend]
Collaboration diagram for CEGUI::LuaScriptModule:
[legend]

List of all members.

## Public Member Functions
void | executeScriptFile (const String &filename, const String &resourceGroup)
| Execute a script file.
void | executeScriptFile (const String &filename, const String &resourceGroup, const String &error_handler)
| Execute a script file.
void | executeScriptFile (const String &filename, const String &resourceGroup, const int error_handler)
| Execute a script file.
int | executeScriptGlobal (const String &function_name)
| Execute a scripted global function. The function should not take any parameters and should return an integer.
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 integer.
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 integer.
bool | executeScriptedEventHandler (const String &handler_name, const EventArgs &e)
| Execute a scripted global 'event handler' function by looking it up by name.
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.
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.
void | executeString (const String &str)
| Execute script code contained in the given CEGUI::String object.
void | executeString (const String &str, const String &error_handler)
| Execute script code contained in the given CEGUI::String object.
void | executeString (const String &str, const int error_handler)
| Execute script code contained in the given CEGUI::String object.
Event::Connection | subscribeEvent (EventSet *target, const String &name, const String &subscriber_name)
| Subscribes the named Event to a scripted funtion.
Event::Connection | subscribeEvent (EventSet *target, const String &name, const String &subscriber_name, const String &error_handler)
| Subscribes the named Event to a scripted funtion.
Event::Connection | subscribeEvent (EventSet *target, const String &name, const String &subscriber_name, const int error_handler)
| Subscribes the named Event to a scripted funtion.
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.
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.
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 | createBindings (void)
| Method called during system initialisation, prior to running any scripts via the ScriptModule, to enable the ScriptModule to perform any operations required to complete initialisation or binding of the script language to the gui system objects.
void | destroyBindings (void)
| Method called during system destruction, after all scripts have been run via the ScriptModule, to enable the ScriptModule to perform any operations required to cleanup bindings of the script language to the gui system objects, as set-up in the earlier createBindings call.
lua_State * | getLuaState (void) const
| Method used to get a pointer to the lua_State that the script module is attached to.
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, unless an alternative is specified in some other function call.
void | setDefaultPCallErrorHandler (int function_reference)
| Set the function that will be passed as the error handler in calls to lua_pcall, unless an alternative is specified in some other function call.
const String & | getActivePCallErrorHandlerString () const
| Return the function name string of the active error handler function.
int | getActivePCallErrorHandlerReference () const
| return the lua registry index of the active error handler function.
## Static Public Member Functions
static LuaScriptModule & | create (lua_State *state=0)
| Creates a LuaScriptModule object.
static void | destroy (LuaScriptModule &mod)
| Destroys the given LuaScriptModule object.

## Detailed Description

Interface for the LuaScriptModule class.

## Member Function Documentation

static LuaScriptModule& CEGUI::LuaScriptModule::create | ( | lua_State * | state = `0` | ) | `[static]`

Creates a LuaScriptModule object.

Parameters:

  state | Pointer to the lua_State that the script module should attach to, if this is 0 a lua_State will be created.

void CEGUI::LuaScriptModule::createBindings | ( | void |  | ) | `[virtual]`

Method called during system initialisation, prior to running any scripts via the ScriptModule, to enable the ScriptModule to perform any operations required to complete initialisation or binding of the script language to the gui system objects.

Returns:
  Nothing.

Reimplemented from CEGUI::ScriptModule.

void CEGUI::LuaScriptModule::destroyBindings | ( | void |  | ) | `[virtual]`

Method called during system destruction, after all scripts have been run via the ScriptModule, to enable the ScriptModule to perform any operations required to cleanup bindings of the script language to the gui system objects, as set-up in the earlier createBindings call.

Returns:
  Nothing.

Reimplemented from CEGUI::ScriptModule.

bool CEGUI::LuaScriptModule::executeScriptedEventHandler | ( | const String & | handler_name,
|  | const EventArgs & | e
| ) |  | `[virtual]`

Execute a scripted global 'event handler' function by looking it up by name.

Parameters:

  handler_name | String object holding the name of the scripted handler function. If this string contains dots '.' it will be parsed as tables containing a function field. For example: 'mytable.subtable.func'
  e | EventArgs based object that should be passed, by any appropriate means, to the scripted function.

Returns:
  - true if the event was handled.
  - false if the event was not handled.

Implements CEGUI::ScriptModule.

bool CEGUI::LuaScriptModule::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.

Parameters:

  handler_name | String object holding the name of the scripted handler function. If this string contains dots '.' it will be parsed as tables containing a function field. For example: 'mytable.subtable.func'
  e | EventArgs based object that should be passed, by any appropriate means, to the scripted function.
  error_handler | String containing the name of the script fuction that will be called if an error occurs while executing the handler function. NB: This is the function passed as the error handler to lua_pcall.

Returns:
  - true if the event was handled.
  - false if the event was not handled.

bool CEGUI::LuaScriptModule::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.

Parameters:

  handler_name | String object holding the name of the scripted handler function. If this string contains dots '.' it will be parsed as tables containing a function field. For example: 'mytable.subtable.func'
  e | EventArgs based object that should be passed, by any appropriate means, to the scripted function.
  error_handler | integer value describing a lua registry reference to the function that will be called if an error occurs while executing the handler function. NB: This is the function passed as the error handler to lua_pcall.

Returns:
  - true if the event was handled.
  - false if the event was not handled.

void CEGUI::LuaScriptModule::executeScriptFile | ( | const String & | filename,
|  | const String & | resourceGroup,
|  | const String & | error_handler
| ) |  |

Execute a script file.

Parameters:

  filename | String object holding the filename of the script file that is to be executed.
  resourceGroup | Resource group idendifier to be passed to the ResourceProvider when loading the script file.
  error_handler | String containing the name of the script fuction that will be called if an error occurs while executing the handler function. NB: This is the function passed as the error handler to lua_pcall.

void CEGUI::LuaScriptModule::executeScriptFile | ( | const String & | filename,
|  | const String & | resourceGroup,
|  | const int | error_handler
| ) |  |

Execute a script file.

Parameters:

  filename | String object holding the filename of the script file that is to be executed.
  resourceGroup | Resource group idendifier to be passed to the ResourceProvider when loading the script file.
  error_handler | integer value describing a lua registry reference to the function that will be called if an error occurs while executing the handler function. NB: This is the function passed as the error handler to lua_pcall.

void CEGUI::LuaScriptModule::executeScriptFile | ( | const String & | filename,
|  | const String & | resourceGroup
| ) |  | `[virtual]`

Execute a script file.

Parameters:

  filename | String object holding the filename of the script file that is to be executed.
  resourceGroup | Resource group idendifier to be passed to the ResourceProvider when loading the script file.

Implements CEGUI::ScriptModule.

int CEGUI::LuaScriptModule::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 integer.

Parameters:

  function_name | String object holding the name of the function, in the global script environment, that is to be executed.
  error_handler | integer value describing a lua registry reference to the function that will be called if an error occurs while executing the handler function. NB: This is the function passed as the error handler to lua_pcall.

Returns:
  The integer value returned from the script function.

int CEGUI::LuaScriptModule::executeScriptGlobal | ( | const String & | function_name | ) | `[virtual]`

Execute a scripted global function. The function should not take any parameters and should return an integer.

Parameters:

  function_name | String object holding the name of the function, in the global script environment, that is to be executed.

Returns:
  The integer value returned from the script function.

Implements CEGUI::ScriptModule.

int CEGUI::LuaScriptModule::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 integer.

Parameters:

  function_name | String object holding the name of the function, in the global script environment, that is to be executed.
  error_handler | String containing the name of the script fuction that will be called if an error occurs while executing the handler function. NB: This is the function passed as the error handler to lua_pcall.

Returns:
  The integer value returned from the script function.

void CEGUI::LuaScriptModule::executeString | ( | const String & | str | ) | `[virtual]`

Execute script code contained in the given CEGUI::String object.

Parameters:

  str | String object holding the valid script code that should be executed.

Returns:
  Nothing.

Implements CEGUI::ScriptModule.

void CEGUI::LuaScriptModule::executeString | ( | const String & | str,
|  | const String & | error_handler
| ) |  |

Execute script code contained in the given CEGUI::String object.

Parameters:

  str | String object holding the valid script code that should be executed.
  error_handler | String containing the name of the script fuction that will be called if an error occurs while executing the handler function. NB: This is the function passed as the error handler to lua_pcall.

Returns:
  Nothing.

void CEGUI::LuaScriptModule::executeString | ( | const String & | str,
|  | const int | error_handler
| ) |  |

Execute script code contained in the given CEGUI::String object.

Parameters:

  str | String object holding the valid script code that should be executed.
  error_handler | integer value describing a lua registry reference to the function that will be called if an error occurs while executing the handler function. NB: This is the function passed as the error handler to lua_pcall.

Returns:
  Nothing.

int CEGUI::LuaScriptModule::getActivePCallErrorHandlerReference | ( |  | ) | const

return the lua registry index of the active error handler function.

The 'active' error handler for the LuaScriptModule is either the default as specified by calling setDefaultPCallErrorHandler, or whatever might have been set up by a call to the internal initErrorHandlerFunc function.

This may return a value previously set by the user, or the value as
  bound internally by the script module for an error handler specified by function name.

Note:
  This function is really intended for use internally by other parts of the lua scripting support. Although it could be useful elsewhere for advanced uses, so long as you're careful!

Warning:
  You should never call luaL_unref on the value returned by this function unless you created tge reference in the first place, and even then only after having called setDefaultPCallErrorHandler passing LUA_NOREF.

const String& CEGUI::LuaScriptModule::getActivePCallErrorHandlerString | ( |  | ) | const

Return the function name string of the active error handler function.

The 'active' error handler for the LuaScriptModule is either the default as specified by calling setDefaultPCallErrorHandler, or whatever might have been set up by a call to the internal initErrorHandlerFunc function.

Note:
  This function is really intended for use internally by other parts of the lua scripting support. Although it could be useful elsewhere for advanced uses, so long as you're careful!

lua_State* CEGUI::LuaScriptModule::getLuaState | ( | void |  | ) | const`[inline]`

Method used to get a pointer to the lua_State that the script module is attached to.

Returns:
  A pointer to the lua_State that the script module is attached to.

void CEGUI::LuaScriptModule::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, unless an alternative is specified in some other function call.

Parameters:

  error_handler_function | Name of the lua function to be called. This is looked up / bound on first usage.

void CEGUI::LuaScriptModule::setDefaultPCallErrorHandler | ( | int | function_reference | ) |

Set the function that will be passed as the error handler in calls to lua_pcall, unless an alternative is specified in some other function call.

Parameters:

  function_reference | Lua function registry index of the function to be called.

Event::Connection CEGUI::LuaScriptModule::subscribeEvent | ( | EventSet * | target,
|  | const String & | name,
|  | const String & | subscriber_name,
|  | const int | error_handler
| ) |  |

Subscribes the named Event to a scripted funtion.

Parameters:

  target | The target EventSet for the subscription.
  name | String object containing the name of the Event to subscribe to.
  subscriber_name | String object containing the name of the script funtion that is to be subscribed to the Event.
  error_handler | integer value describing a lua registry reference to the function that will be called if an error occurs while executing the handler function. NB: This is the function passed as the error handler to lua_pcall.

Returns:
  Connection object that can be used to check the status of the Event connection and to disconnect (unsubscribe) from the Event.

Event::Connection CEGUI::LuaScriptModule::subscribeEvent | ( | EventSet * | target,
|  | const String & | name,
|  | const String & | subscriber_name
| ) |  | `[virtual]`

Subscribes the named Event to a scripted funtion.

Parameters:

  target | The target EventSet for the subscription.
  name | String object containing the name of the Event to subscribe to.
  subscriber_name | String object containing the name of the script funtion that is to be subscribed to the Event.

Returns:
  Connection object that can be used to check the status of the Event connection and to disconnect (unsubscribe) from the Event.

Implements CEGUI::ScriptModule.

Event::Connection CEGUI::LuaScriptModule::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.

Parameters:

  target | The target EventSet for the subscription.
  name | String object containing the name of the Event to subscribe to.
  group | Group which is to be subscribed to. Subscription groups are called in ascending order.
  subscriber_name | String object containing the name of the script funtion that is to be subscribed to the Event.
  error_handler | String containing the name of the script fuction that will be called if an error occurs while executing the handler function. NB: This is the function passed as the error handler to lua_pcall.

Returns:
  Connection object that can be used to check the status of the Event connection and to disconnect (unsubscribe) from the Event.

Event::Connection CEGUI::LuaScriptModule::subscribeEvent | ( | EventSet * | target,
|  | const String & | name,
|  | Event::Group | group,
|  | const String & | subscriber_name
| ) |  | `[virtual]`

Subscribes the specified group of the named Event to a scripted funtion.

Parameters:

  target | The target EventSet for the subscription.
  name | String object containing the name of the Event to subscribe to.
  group | Group which is to be subscribed to. Subscription groups are called in ascending order.
  subscriber_name | String object containing the name of the script funtion that is to be subscribed to the Event.

Returns:
  Connection object that can be used to check the status of the Event connection and to disconnect (unsubscribe) from the Event.

Implements CEGUI::ScriptModule.

Event::Connection CEGUI::LuaScriptModule::subscribeEvent | ( | EventSet * | target,
|  | const String & | name,
|  | const String & | subscriber_name,
|  | const String & | error_handler
| ) |  |

Subscribes the named Event to a scripted funtion.

Parameters:

  target | The target EventSet for the subscription.
  name | String object containing the name of the Event to subscribe to.
  subscriber_name | String object containing the name of the script funtion that is to be subscribed to the Event.
  error_handler | String containing the name of the script fuction that will be called if an error occurs while executing the handler function. NB: This is the function passed as the error handler to lua_pcall.

Returns:
  Connection object that can be used to check the status of the Event connection and to disconnect (unsubscribe) from the Event.

Event::Connection CEGUI::LuaScriptModule::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.

Parameters:

  target | The target EventSet for the subscription.
  name | String object containing the name of the Event to subscribe to.
  group | Group which is to be subscribed to. Subscription groups are called in ascending order.
  subscriber_name | String object containing the name of the script funtion that is to be subscribed to the Event.
  error_handler | integer value describing a lua registry reference to the function that will be called if an error occurs while executing the handler function. NB: This is the function passed as the error handler to lua_pcall.

Returns:
  Connection object that can be used to check the status of the Event connection and to disconnect (unsubscribe) from the Event.