nrEngine::ScriptEngine Class Reference
[Engine Scripting]

Script engine is a glue code between the scripts and the engine. More...


Public Member Functions

Result add (const std::string &name, ScriptFunctor func, const std::vector< ScriptParam > &param=std::vector< ScriptParam >())
Result add (const std::string &name, ScriptFunctor func, const VarArg &v)
Result del (const std::string &name)
ScriptResult call (const std::string &name, const std::vector< std::string > &args=std::vector< std::string >())
ResourcePtr< IScriptload (const std::string &name, const std::string &fileName)
Result execute (const std::string &name, bool runOnce=true, bool immediate=false)
Result execute (const std::string &name, const std::string &fileName, bool runOnce=true, bool immediate=false)
NR_FORCEINLINE uint32 getFunctionCount () const
const std::string & getFunction (uint32 index, ScriptFunctor &functor)

Static Public Member Functions

template<class T>
static T parameter_cast (const ScriptParam &p)

Friends

class Engine
 Only engine is allowed to create the instances.


Detailed Description

Script engine is a glue code between the scripts and the engine.

The script engine is a main class representing the glue code between the scripting languages (from plugins or whatever) and the game engine. The game engine will register functions by the script engine, so you get an access to this functions in your scripts. So the script engine class is something like an engine's API for the scripts.

In the future we want to improve the functionality of the scripting engine, by adding the possibility to use meta classes. So the scripts could create new classes based on engine's.

Definition at line 57 of file ScriptEngine.h.


Member Function Documentation

template<class T>
static T nrEngine::ScriptEngine::parameter_cast ( const ScriptParam p  )  [static]

Cast a script parameter, which is of type "any", to any other type. Note: we use here any_cast, so you have to worry about catching the error throws

Definition at line 66 of file ScriptEngine.h.

Result nrEngine::ScriptEngine::add ( const std::string &  name,
ScriptFunctor  func,
const std::vector< ScriptParam > &  param = std::vector< ScriptParam >() 
)

Register new functions, that can be called from scripts. The functions registered here are called through call() method.

You can also specify one default parameter, that will be passed to the called function (e.g. pointer to your object). The parameter is of the boost type "any". So it does not have certain type.

Parameters:
name Name of the function, must be unique
func Function itself (i.e. boost::function)
param Parameters you want to be stored to pass later to the function
Returns:
either OK or an error code if there is some problems

Definition at line 169 of file ScriptEngine.cpp.

References nrEngine::EventManager::emitSystem(), nrEngine::Log::LL_DEBUG, nrEngine::Log::LOG_ENGINE, nrEngine::OK, nrEngine::SCRIPT_FUNCTION_REGISTERED, and nrEngine::Engine::sEventManager().

Referenced by add(), nrEngine::DefaultScriptingFunctions::addMethods(), nrEngine::Clock::onStartTask(), and nrEngine::PluginLoader::PluginLoader().

Result nrEngine::ScriptEngine::add ( const std::string &  name,
ScriptFunctor  func,
const VarArg v 
)

Using variable parameter arguments.

See also:
add()

Definition at line 190 of file ScriptEngine.cpp.

References add(), and nrEngine::VarArg::convert().

Result nrEngine::ScriptEngine::del ( const std::string &  name  ) 

Delete already registered function from the api database.

Parameters:
name name of the function to be deregistered
Returns:
either OK or an error code

Definition at line 201 of file ScriptEngine.cpp.

References nrEngine::EventManager::emitSystem(), nrEngine::Log::LL_DEBUG, nrEngine::Log::LOG_ENGINE, nrEngine::OK, nrEngine::SCRIPT_FUNCTION_NOT_REGISTERED, and nrEngine::Engine::sEventManager().

Referenced by nrEngine::DefaultScriptingFunctions::delMethods(), nrEngine::Clock::stopTask(), nrEngine::PluginLoader::~PluginLoader(), and nrEngine::ResourceManager::~ResourceManager().

ScriptResult nrEngine::ScriptEngine::call ( const std::string &  name,
const std::vector< std::string > &  args = std::vector< std::string >() 
)

Call a certain function from the database whithin the given parameters. First script engine database will look if there is a function whithin the given name. Then if such could be found the functor according to the function will be called. As first parameter it sends the user predefined parameters, stored in the database. As second it will pass the string parameters coming from the script or from the subroutine called this method.

Parameters:
name Unique name of hte function to be called
args Argument list of arguments given to the function (like in the console, first must always be the function name)

Definition at line 220 of file ScriptEngine.cpp.

References nrEngine::Log::LL_DEBUG, nrEngine::Log::LL_WARNING, and nrEngine::Log::LOG_ENGINE.

Referenced by nrEngine::Script::fullRun().

ResourcePtr< IScript > nrEngine::ScriptEngine::load ( const std::string &  name,
const std::string &  fileName 
)

Load a new script from the given file. The script will be loaded by the resource manager, which will try to find the appropriate loader for this type of scripts. If there is no such loader could be found, so null will be returned. Otherwise you get a resource pointer to the script. The resource pointer garanty that the according script will be used in the way like all other resources. This means if a script is unloaded,so EmptyScript will be used. You do not have to care about given pointers, because resource pointers have similar behaviours as smart pointers.

The function does load the scripts in the memory, so you do not have to carry about the returned pointer, if you do not want to. Loaded scripts are still accessable by their names.

Parameters:
name Name for the script.
fileName Name of the file containign the script.
Returns:
ResourcePtr<IScript> to the script.

Definition at line 256 of file ScriptEngine.cpp.

References nrEngine::IResourcePtr::isNull(), nrEngine::Log::LL_ERROR, nrEngine::ResourceManager::loadResource(), nrEngine::Log::LOG_ENGINE, and nrEngine::Engine::sResourceManager().

Referenced by execute(), and nrEngine::ScriptFunctionDec().

Result nrEngine::ScriptEngine::execute ( const std::string &  name,
bool  runOnce = true,
bool  immediate = false 
)

This method will execute script of a certain name loaded before with loadScript() method.

Parameters:
name Unique name for the script
runOnce If true the script will be executed only one time
immediate If true the script will be run immediately. If false the script will be added as a task into the kernel, and will be started in the next execution cycle.
Returns:
Returning code of IScript::execute() method.

Definition at line 269 of file ScriptEngine.cpp.

References nrEngine::ResourceManager::getByName(), and nrEngine::Engine::sResourceManager().

Result nrEngine::ScriptEngine::execute ( const std::string &  name,
const std::string &  fileName,
bool  runOnce = true,
bool  immediate = false 
)

Combined method of load() and execute(). See documentation for them instead

Definition at line 277 of file ScriptEngine.cpp.

References load().

NR_FORCEINLINE uint32 nrEngine::ScriptEngine::getFunctionCount (  )  const

Get count of functions registered in the database

Definition at line 161 of file ScriptEngine.h.

Referenced by getFunction(), and nrEngine::ScriptConnector::initialize().

const std::string & nrEngine::ScriptEngine::getFunction ( uint32  index,
ScriptFunctor functor 
)

Return an functor element of a certain index from the database. Any functor element is a pair of the functor and script parameters defined by the user.

Definition at line 292 of file ScriptEngine.cpp.

References getFunctionCount(), and NR_ASSERT.

Referenced by nrEngine::ScriptConnector::initialize().


The documentation for this class was generated from the following files:
Generated on Wed Sep 12 23:19:43 2007 for nrEngine by  doxygen 1.5.1