Cafu Engine
ConsoleInterpreterI Class Referenceabstract

This class is an interface to the console interpreter. More...

#include "ConsoleInterpreter.hpp"

Inheritance diagram for ConsoleInterpreterI:

Public Member Functions

virtual ~ConsoleInterpreterI ()
 Virtual dtor so that derived classes properly destroy. More...
 
virtual void Register (ConVarT *ConVar)=0
 Registers a convar with the console interpreter. More...
 
virtual void Register (ConFuncT *ConFunc)=0
 Registers a confunc with the console interpreter. More...
 
virtual void Unregister (ConVarT *ConVar)=0
 Unregisters the given convar from the interpreter again. More...
 
virtual void Unregister (ConFuncT *ConFunc)=0
 Unregisters the given confunc from the interpreter again. More...
 
virtual ConFuncTFindFunc (const std::string &Name)=0
 Finds the confunc with the given name. More...
 
virtual ConVarTFindVar (const std::string &Name)=0
 Finds the convar with the given name. More...
 
virtual std::string LineCompletion (const std::string &LineBegin, ArrayT< std::string > &Completions)=0
 This method provides command-line completion for this interpreter. More...
 
virtual bool RunCommand (const std::string &Input)=0
 Compiles and runs the given Lua statements. More...
 

Static Public Member Functions

static void RegisterLua (lua_State *LuaState)
 Registers the methods of this interface with LuaState as a Lua module as described in the PiL2 book, chapter 26.2. More...
 

Detailed Description

This class is an interface to the console interpreter.

User code can register its convars and confuncs with it so that they can be used in the context of the interpreter. For each application, there is only one, global, application-wide, unique implementation of the console interpreter, typically in the main exe, and the exe and all dlls each have a pointer to it.

Constructor & Destructor Documentation

virtual ConsoleInterpreterI::~ConsoleInterpreterI ( )
inlinevirtual

Virtual dtor so that derived classes properly destroy.

Member Function Documentation

virtual ConFuncT* ConsoleInterpreterI::FindFunc ( const std::string &  Name)
pure virtual

Finds the confunc with the given name.

Parameters
NameThe name of the confunc to find.
Returns
the pointer to the confunc, or NULL if a confunc with that name does not exist.

Implemented in ConsoleInterpreterImplT.

virtual ConVarT* ConsoleInterpreterI::FindVar ( const std::string &  Name)
pure virtual

Finds the convar with the given name.

Parameters
NameThe name of the convar to find.
Returns
the pointer to the convar, or NULL if a convar with that name does not exist.

Implemented in ConsoleInterpreterImplT.

virtual std::string ConsoleInterpreterI::LineCompletion ( const std::string &  LineBegin,
ArrayT< std::string > &  Completions 
)
pure virtual

This method provides command-line completion for this interpreter.

It returns all available completions for the last token in the given string LineBegin in the Completions array. Note that the completions not only cover the registered ConFuncTs and ConVarTs, but also any other user- and implementation-defined symbols.

Parameters
LineBeginThe incomplete command-line string for whose last token the method is supposed to provide completions for. For example, if LineBegin is "a=GetValueX()*Get", the method is supposed to look for completions for "Get".
CompletionsThe found completions are returned here as complete tokens. For example, if LineBegin is "a=GetValueX()*Get", Completions may contain the strings "GetValueX" and "GetValueY". The caller can therefore not do much (i.e. concat to input string) with the returned strings but print them out.
Returns
the longest expansion substring for LineBegin that works with all completions. The caller can simply concatenate this string to LineBegin to implement incremental completions. In the context of the above examples, "Value" would be the expected return string.

Implemented in ConsoleInterpreterImplT.

virtual void ConsoleInterpreterI::Register ( ConVarT ConVar)
pure virtual

Registers a convar with the console interpreter.

This method is normally not called by user code, but by the implementation of the ConVarT ctors and ConVarT::RegisterStaticList().

Parameters
ConVarThe console variable to register with this interpreter.

Implemented in ConsoleInterpreterImplT.

virtual void ConsoleInterpreterI::Register ( ConFuncT ConFunc)
pure virtual

Registers a confunc with the console interpreter.

This method is normally not called by user code, but by the implementation of the ConFuncT ctors and ConFuncT::RegisterStaticList().

Parameters
ConFuncThe console function to register with this interpreter.

Implemented in ConsoleInterpreterImplT.

void ConsoleInterpreterI::RegisterLua ( lua_State *  LuaState)
static

Registers the methods of this interface with LuaState as a Lua module as described in the PiL2 book, chapter 26.2.

The key idea is that all methods are called via the global ConsoleInterpreter variable defined below, and therefore we may consider them as a collection of C-style functions (no OO involved), so that putting them in a Lua table as described in chapter 26 of the PiL2 book is straightforward.

virtual bool ConsoleInterpreterI::RunCommand ( const std::string &  Input)
pure virtual

Compiles and runs the given Lua statements.

Parameters
InputThe string with the Lua statements that is to be compiled and run within this console state.
Returns
true if the command has been successfully loaded (compiled) and run, false otherwise.

Implemented in ConsoleInterpreterImplT.

virtual void ConsoleInterpreterI::Unregister ( ConVarT ConVar)
pure virtual

Unregisters the given convar from the interpreter again.

Parameters
ConVarThe console variable to unregister from this interpreter.

Implemented in ConsoleInterpreterImplT.

virtual void ConsoleInterpreterI::Unregister ( ConFuncT ConFunc)
pure virtual

Unregisters the given confunc from the interpreter again.

Parameters
ConFuncThe console function to unregister from this interpreter.

Implemented in ConsoleInterpreterImplT.


The documentation for this class was generated from the following files: