NAP
Public Member Functions | List of all members
PythonScriptComponentInstance Class Reference

#include <pythonscriptcomponent.h>

Public Member Functions

 PythonScriptComponentInstance (EntityInstance &entity, Component &resource)
 
 ~PythonScriptComponentInstance ()
 
virtual void update (double deltaTime) override
 
bool init (utility::ErrorState &errorState) override
 
template<typename ReturnType , typename ... Args>
bool get (const std::string &identifier, utility::ErrorState &errorState, ReturnType &returnValue, Args &&... args)
 
template<typename ... Args>
bool call (const std::string &identifier, utility::ErrorState &errorState, Args &&... args)
 
- Public Member Functions inherited from ComponentInstance
 ComponentInstance (EntityInstance &entity, Component &resource)
 
nap::EntityInstancegetEntityInstance () const
 
nap::ComponentgetComponent () const
 
template<typename T >
T * getComponent () const
 
virtual bool init (utility::ErrorState &errorState)
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
virtual void onDestroy ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Description

The instance part of the PythonScriptComponent. Allows for running a python script inside a NAP application. The python script has to implement a class with the name of the ClassName property. The class should implement:

Inheritance diagram for PythonScriptComponentInstance:
[legend]
Collaboration diagram for PythonScriptComponentInstance:
[legend]

Constructor & Destructor Documentation

◆ PythonScriptComponentInstance()

PythonScriptComponentInstance ( EntityInstance entity,
Component resource 
)

◆ ~PythonScriptComponentInstance()

Member Function Documentation

◆ call()

bool call ( const std::string &  identifier,
utility::ErrorState errorState,
Args &&...  args 
)

Tries to call a method in the python script with the specified number of input arguments. The identifier is the name of the python method to call. If the call fails the error will be logged in errorState.

Parameters
identifierpython method to call
errorStatecontains the error if the call fails
argsvariable number of input arguments.
Returns
if the call succeeded

◆ get()

bool get ( const std::string &  identifier,
utility::ErrorState errorState,
ReturnType &  returnValue,
Args &&...  args 
)

Tries to call a method that returns a value in the python script with the specified number of input arguments. The return value will be stored in returnValue, the identifier is the name of the python method to call. If the call fails the error will be logged in errorState.

Parameters
identifierpython method to call.
errorStatecontains the error if the call fails.
returnValuethe populated return value
argsvariable number of input arguments.
Returns
if the call succeeded.

◆ init()

bool init ( utility::ErrorState errorState)
overridevirtual

Initializes this component based on it's resource.

Parameters
errorStatecontains the error when initialization fails.
Returns
if initialization succeeded.

Reimplemented from ComponentInstance.

◆ update()

virtual void update ( double  deltaTime)
overridevirtual

Update this component

Parameters
deltaTimethe time in between cooks in seconds

Reimplemented from ComponentInstance.