NAP
Public Member Functions | Public Attributes | List of all members
PythonScript Class Reference

#include <pythonscript.h>

Public Member Functions

 PythonScript (PythonScriptService &service)
 
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)
 
pybind11::object get (const std::string &symbol)
 
- Public Member Functions inherited from Resource
 Resource ()
 
- 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
 

Public Attributes

std::string mPath
 property: 'Path' Path to the python script. More...
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 

Description

A python script loaded from a text file into a pybind11 module. Functions within the script can be called using the call() method and handles to functions and classes can be acquired using get()

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

Constructor & Destructor Documentation

◆ PythonScript()

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 arguments. If the call fails the error will be logged in errorState.

Parameters
identifiername of the function to call
errorStatecontains the error if the call fails
argsadditional input arguments

◆ get() [1/2]

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

Tries to call a method with the given name and arguments. The return value is stored in 'returnValue'. If the call fails the error will be logged in errorState.

Parameters
identifierthe name of the function to call
errorStatecontains the error if the call fails
returnValuethe return value of the call
argsadditional input arguments

◆ get() [2/2]

pybind11::object get ( const std::string &  symbol)

Requests a symbol (in most cases a class or function) from the script and returns its C++ representation.

Returns
the python C++ symbol representation

◆ init()

bool init ( utility::ErrorState errorState)
overridevirtual

Override this method to initialize the object after de-serialization. When called it is safe to assume that all dependencies have been resolved up to this point.

Parameters
errorStateshould contain the error message when initialization fails.
Returns
if initialization succeeded or failed.

Reimplemented from Object.

Member Data Documentation

◆ mPath

std::string mPath

property: 'Path' Path to the python script.