Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

mortic::IScript Class Reference

A wrapper to a python script. More...

Inheritance diagram for mortic::IScript:

mortic::IObject List of all members.

Public Member Functions

 IScript (IRoot *root)
 Constructor.
virtual ~IScript ()
 Destructor.
virtual void runSimpleString (std::string str)=0
 Run a string in the script's namespace.
virtual bool variableExists (std::string var)=0
 Check if a variable exists.
virtual float callFunction (std::string name, std::string format,...)=0
 Call a function.
virtual std::string getNamespace ()=0
 Returns the name of the namespace dictionary.
virtual void pushValue (float val)=0
 Push a value on to the virtual stack.
virtual float popValue ()=0
 Pop a value from the virtual stack.

Detailed Description

A wrapper to a python script.

This is the C++ interface to access python scripts loaded in IScriptManager. In all python code, this object can be found in "self". Thus, a python script can call "self.popValue()" to pop a value off the virtual stack. Read more about that in pushValue()

Definition at line 34 of file IScriptManager.h.


Constructor & Destructor Documentation

mortic::IScript::IScript IRoot root  )  [inline]
 

Constructor.

Definition at line 38 of file IScriptManager.h.

virtual mortic::IScript::~IScript  )  [inline, virtual]
 

Destructor.

Definition at line 41 of file IScriptManager.h.


Member Function Documentation

virtual float mortic::IScript::callFunction std::string  name,
std::string  format,
  ...
[pure virtual]
 

Call a function.

This is a combination function that calls a function in python with the arguments given, converted into the appropriate type. The format argument is a string that gives the format of the arguments to come, much like C's printf. A 'b' sends a bool, an 'i' sends an int, and a 'f' sends a float. Objects can be identified by '<Object>', where 'Object' is the class name minus the 'I'. Example: "callFunction("test", "b<LogManager>", true, someLogManager)" calls "test(True, someLogManager)" in Python. Just expect this function to work the way it should. Note: normal, unspecific objects are identified by "<>".

  • name - the name of the function to call
  • format - the argument format
  • ... - arguments to call the function with
    Returns:
    the float-version of what the call returned

virtual std::string mortic::IScript::getNamespace  )  [pure virtual]
 

Returns the name of the namespace dictionary.

Not for the faint of heart. This returns the namespace dictionary that this script runs in, which is a hash of the source of the script.

Returns:
the script's namespace

virtual float mortic::IScript::popValue  )  [pure virtual]
 

Pop a value from the virtual stack.

See pushValue() for more info on the virtual stack.

Returns:
the value from the stack
See also:
pushValue()

virtual void mortic::IScript::pushValue float  val  )  [pure virtual]
 

Push a value on to the virtual stack.

This function pushes a float onto the virtual stack. What is the VS? Well, normally exchanging values between C and Python is a bit of a pain, especially in a portable way. One way to overcome it is to use a virtual stack of floating-point numbers. Because the script can reference itself with "self", the script can take values off the stack that C put there. So, I can pushValue(3.14) in C, then self.popValue() in Python would return 3.14! Why a float? Almost every value in Mortic can be represented as a float. Integers, floats, even IObjects when referenced by ID! Warning: Items are popped off the stack in the reverse of the order they were pushed. Think of a stack of papers: You can only take off the one you just put on top.

  • val - the float to push onto the stack

virtual void mortic::IScript::runSimpleString std::string  str  )  [pure virtual]
 

Run a string in the script's namespace.

This runs the python command(s) given in the scripts namespace. This is how you call functions and basically do anything.

  • str - the python commands to run

virtual bool mortic::IScript::variableExists std::string  var  )  [pure virtual]
 

Check if a variable exists.

This returns whether or not the variable given exists in the script's namespace.

  • var - the variable to check for
    Returns:
    true if the variable exists


Generated on Sat Dec 30 21:21:59 2006 for mortic by  doxygen 1.4.4