|  | overview |  | wiki |  | api reference |  | download

- Main Page
- Classes

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

All Classes Functions Variables Typedefs Enumerations Enumerator
Classes | Public Member Functions | Protected Member Functions | Protected Attributes
gameplay::ScriptTarget Class Reference

`#include <ScriptTarget.h>`

Inheritance diagram for gameplay::ScriptTarget:

List of all members.

## Classes

struct | CallbackFunction
class | Event
class | EventRegistry
struct | RegistryEntry
struct | ScriptEntry

## Public Member Functions

virtual const char * | getTypeName () const =0
Script * | addScript (const char *path)
bool | removeScript (const char *path)
void | addScriptCallback (const Event *event, const char *function)
void | removeScriptCallback (const Event *event, const char *function)
void | clearScripts ()
bool | hasScriptListener (const char *eventName) const
bool | hasScriptListener (const Event *event) const
const Event * | getScriptEvent (const char *eventName) const
template<typename T >
T | fireScriptEvent (const Event *event,...)

## Protected Member Functions

| ScriptTarget ()
virtual | ~ScriptTarget ()
void | removeScript (ScriptEntry *entry)
void | registerEvents (EventRegistry *registry)

## Protected Attributes

RegistryEntry * | _scriptRegistries
ScriptEntry * | _scripts
std::map< const Event *, std::vector < CallbackFunction > > * | _scriptCallbacks

## Detailed Description

Defines an interface for supporting script callbacks.

Classes that extend ScriptTarget can expose script events using the GP_SCRIPT_EVENT macros. Custom events should be registered using these macros at the top of the class definition. Events can be fired by calling the ScriptTarget::fireScriptEvent method, passing the registered ScriptTarget::Event object and any required parameters.

In addition to script events that are explicitly defined by a custom ScriptTarget class, all ScriptTarget scripts implicitly support an "attached" event. This event is called immediately after such a script is attached to a ScriptTarget and it takes a single parameter: the ScriptTarget object.

## Constructor & Destructor Documentation

gameplay::ScriptTarget::ScriptTarget | ( |  | ) | `[protected]`

Constructor.

virtual gameplay::ScriptTarget::~ScriptTarget | ( |  | ) | `[protected, virtual]`

Destructor.

## Member Function Documentation

Script* gameplay::ScriptTarget::addScript | ( | const char * | path | ) |

Attaches a script to this object.

Scripts attached to a ScriptTarget are loaded using the PROTECTED scope, which loads scripts into their own protected script environment, allowing variables with the same name to be used without colliding with other scripts.

Parameters:

  path | Path to the script.

Returns:
  A pointer to the successfully loaded script, or NULL if unsuccessful.

void gameplay::ScriptTarget::addScriptCallback | ( | const Event * | event,
|  | const char * | function
| ) |  |

Adds the given global script function as a callback for the given event.

Individual script callback events registered via this method are expected to be global script functions. Registering individual callbacks in this manner is generally slower than registering a single script to handle script events for an object.

Parameters:

  event | The event to add the callback for.
  function | The name of the script function to call when the event is fired; can either be just the name of a function (if the function's script file has already been loaded), or can be a URL of the form scriptFile.lua::functionName.

void gameplay::ScriptTarget::clearScripts | ( |  | ) |

Removes all scripts and callbacks from this object.

bool gameplay::ScriptTarget::fireScriptEvent< bool > | ( | const Event * | event,
|  |  | ...
| ) |  |

Fires the specified script event, passing the specified arguments.

The only supported return types are void and boolean. When a boolean return type is used and there are multiple scripts registered for the given script event, event delegation will stop at the first script that returns a value of true.

Parameters:

  event | The script event to fire, which was returned from EventRegistry::addEvent.
  ... | Optional list of arguments to pass to the script event (should match the script event argument definition).

The fire script event template specialization.

Parameters:

  event | The event fired.
  ... | Optional list of arguments to pass to the script event.

Template specialization.

Parameters:

  evt | The event fired.
  ... | Optional list of arguments to pass to the script event (should match the script event argument definition).

const Event* gameplay::ScriptTarget::getScriptEvent | ( | const char * | eventName | ) | const

Gets the event object for the given event name, if it exists.

Parameters:

  eventName | Name of the event.

Returns:
  The event object for the given name, or NULL if no such event exists.

virtual const char* gameplay::ScriptTarget::getTypeName | ( |  | ) | const`[pure virtual]`

Gets the type name identifier for the class that extends ScriptTarget.

Returns:
  A string describing the type name of the ScriptTarget child class, as it is defined in the lua bindings (i.e. "Node").

Implemented in gameplay::Control, gameplay::Transform, gameplay::PhysicsController, gameplay::Form, gameplay::AnimationClip, gameplay::Node, gameplay::Container, gameplay::Button, gameplay::TextBox, gameplay::ImageControl, gameplay::RadioButton, gameplay::Slider, gameplay::CheckBox, gameplay::JoystickControl, and gameplay::Label.

bool gameplay::ScriptTarget::hasScriptListener | ( | const char * | eventName | ) | const

Determines if there is a script installed that is listening for the given script event (i.e. has a function callback defined for the given event).

Parameters:

  eventName | The script event to check.

Returns:
  True if there is a listener for the specified event, false otherwise.

bool gameplay::ScriptTarget::hasScriptListener | ( | const Event * | event | ) | const

Determines if there is a script installed that is listening for the given script event (i.e. has a function callback defined for the given event).

Parameters:

  event | The script event to check.

Returns:
  True if there is a listener for the specified event, false otherwise.

void gameplay::ScriptTarget::registerEvents | ( | EventRegistry * | registry | ) | `[protected]`

Registers a set of supported script events and event arguments for this ScriptTarget.

The passed in EventRegistry object should contain a list of all script events to be supported by this ScriptTarget, along with their parameter definitions. This registry object will be held onto for the lifetime of the ScriptTarget and it is recommended that it be shared among all ScriptTargets of the same class/type.

This should normally be set using the GP_REGISTER_SCRIPT_EVENTS macro in the constructor of the child class.

Parameters:

  registry | The EventRegistry containing the list of supported script events.

bool gameplay::ScriptTarget::removeScript | ( | const char * | path | ) |

Removes a previously attached script from this object.

Parameters:

  path | The same path that was used to load the script being removed.

Returns:
  True if a script is successfully removed, false otherwise.

void gameplay::ScriptTarget::removeScript | ( | ScriptEntry * | entry | ) | `[protected]`

Removes the specified script.

Parameters:

  entry | The script entry to be removed.

void gameplay::ScriptTarget::removeScriptCallback | ( | const Event * | event,
|  | const char * | function
| ) |  |

Removes the given script function as a callback for the given event.

Parameters:

  event | The event to remove the callback for.
  function | The name of the script function.

## Member Data Documentation

std::map<const Event*, std::vector<CallbackFunction> >* gameplay::ScriptTarget::_scriptCallbacks `[protected]`

Holds the list of callback functions registered for this ScriptTarget.

RegistryEntry* gameplay::ScriptTarget::_scriptRegistries `[protected]`

Holds the event registries for this script target.

ScriptEntry* gameplay::ScriptTarget::_scripts `[protected]`

Holds the list of scripts referenced by this ScriptTarget.

All Classes Functions Variables Typedefs Enumerations Enumerator