HoverRace  2.0
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Private Member Functions | Private Attributes | List of all members
HoverRace::Script::Env Class Referenceabstract

A script environment. More...

#include <Env.h>

+ Inheritance diagram for HoverRace::Script::Env:

Public Member Functions

 Env (Core &scripting)
 Constructor. More...
 
 Env (const Env &)=delete
 
virtual ~Env ()
 
Envoperator= (const Env &)=delete
 
bool RunScript (const Util::OS::path_t &filename)
 Execute a script from a file. More...
 

Protected Member Functions

void CopyGlobals ()
 Copy the global environment into the current table at the top of the stack. More...
 
template<class ReturnPolicy = Core::PrintReturn>
int Execute (const Core::Chunk &chunk, ReturnPolicy rp=ReturnPolicy())
 Execute a chunk of code in the current environment. More...
 
CoreGetScripting () const
 
lua_State * GetState () const
 
virtual void InitEnv ()=0
 Initialize the environment in which scripts will run in. More...
 
void LogScriptError (const Script::ScriptExn &ex)
 
void PushEnv ()
 Push the environment onto the stack. More...
 
void SetHelpHandler (Help::HelpHandler *helpHandler)
 

Static Protected Member Functions

static Core::Chunk LoadChunkFromFile (const Util::OS::path_t &filename)
 Load a chunk from a file. More...
 

Private Member Functions

void SetupEnv ()
 Apply the environment to the function on the top of the stack. More...
 

Private Attributes

RegistryRef envRef
 
Help::HelpHandlerhelpHandler
 
bool initialized
 
Corescripting
 

Detailed Description

A script environment.

Author
Michael Imamura

Constructor & Destructor Documentation

HoverRace::Script::Env::Env ( Core scripting)

Constructor.

Parameters
scriptingThe scripting engine.
HoverRace::Script::Env::Env ( const Env )
delete
virtual HoverRace::Script::Env::~Env ( )
inlinevirtual

Member Function Documentation

void HoverRace::Script::Env::CopyGlobals ( )
protected

Copy the global environment into the current table at the top of the stack.

This is meant to be called from InitEnv() as a convenience.

template<class ReturnPolicy = Core::PrintReturn>
int HoverRace::Script::Env::Execute ( const Core::Chunk chunk,
ReturnPolicy  rp = ReturnPolicy() 
)
inlineprotected

Execute a chunk of code in the current environment.

Parameters
chunkThe code to execute.
rpOptional policy to handle return values.
Returns
The number of return values remaining on the stack, determined by the ReturnPolicy.
Exceptions
IncompleteExnIf the code does not complete a statement; i.e., expecting more tokens. Callers can catch this to keep reading more data to finish the statement.
ScriptExnThe code either failed to compile or signaled an error while executing.
Core& HoverRace::Script::Env::GetScripting ( ) const
inlineprotected
lua_State* HoverRace::Script::Env::GetState ( ) const
inlineprotected
void HoverRace::Script::Env::InitEnv ( )
protectedpure virtual

Initialize the environment in which scripts will run in.

Upon entry, the Lua stack will have at least one entry, the table which represents the environment. Implementing functions will fill this table with the globals which will be available to the functions which are run in this environment. Upon return, this same table must be at the top of the stack.

Implemented in HoverRace::Client::HoverScript::SysConsole, HoverRace::Client::HoverScript::StyleEnv, HoverRace::Client::HoverScript::RulebookEnv, HoverRace::Client::HoverScript::SysEnv, and HoverRace::Client::HoverScript::Console.

Core::Chunk HoverRace::Script::Env::LoadChunkFromFile ( const Util::OS::path_t filename)
staticprotected

Load a chunk from a file.

The chunk name will be based on the filename.

Parameters
filenameThe filename.
Returns
The loaded chunk, ready for compilation.
Exceptions
Script::ScriptExnThe script file was not found.
void HoverRace::Script::Env::LogScriptError ( const Script::ScriptExn ex)
protected
Env& HoverRace::Script::Env::operator= ( const Env )
delete
void HoverRace::Script::Env::PushEnv ( )
protected

Push the environment onto the stack.

InitEnv() will be called if the initial environment hasn't been set.

bool HoverRace::Script::Env::RunScript ( const Util::OS::path_t filename)
inline

Execute a script from a file.

If there is an error executing the script, then the error message will be written to the error log and the function will return false.

Parameters
filenameThe script filename (must be an absolute path).
Returns
true if the script executed successfully, false if there was an error.
void HoverRace::Script::Env::SetHelpHandler ( Help::HelpHandler helpHandler)
protected
void HoverRace::Script::Env::SetupEnv ( )
private

Apply the environment to the function on the top of the stack.

The environment will be initialized for the first time if needed.

The function will remain on the stack afterwards.

Member Data Documentation

RegistryRef HoverRace::Script::Env::envRef
private
Help::HelpHandler* HoverRace::Script::Env::helpHandler
private
bool HoverRace::Script::Env::initialized
private
Core& HoverRace::Script::Env::scripting
private

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