HoverRace  2.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
HoverRace::Client::HoverScript::RulebookEnv Class Reference

Limited environment for defining rulebooks. More...

#include <RulebookEnv.h>

+ Inheritance diagram for HoverRace::Client::HoverScript::RulebookEnv:

Public Member Functions

 RulebookEnv (Script::Core &scripting, const Util::OS::path_t &basePath, Rulebook &rulebook)
 Constructor. More...
 
virtual ~RulebookEnv ()
 
void DefineRulebook (const std::string &name, const luabind::object &defn)
 
bool RunRulebookScript ()
 Run the boot script for a rulebook. More...
 
- Public Member Functions inherited from HoverRace::Client::HoverScript::RuntimeEnv
 RuntimeEnv (Script::Core &scripting)
 
virtual ~RuntimeEnv ()
 
- Public Member Functions inherited from HoverRace::Script::Env
 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...
 

Static Public Member Functions

static int LPlayer (lua_State *L)
 
static int LRequire (lua_State *L)
 
static int LRulebookStage1 (lua_State *L)
 
static int LRulebookStage2 (lua_State *L)
 
static int LSession (lua_State *L)
 

Protected Member Functions

void InitCFn (const char *name, lua_CFunction fn)
 Register a member function in a table. More...
 
virtual void InitEnv ()
 Initialize the environment in which scripts will run in. More...
 
- Protected Member Functions inherited from HoverRace::Script::Env
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
 
void LogScriptError (const Script::ScriptExn &ex)
 
void PushEnv ()
 Push the environment onto the stack. More...
 
void SetHelpHandler (Help::HelpHandler *helpHandler)
 

Private Types

using SUPER = RuntimeEnv
 

Private Member Functions

void DefineRules (const luabind::object &rulesObj)
 

Static Private Member Functions

static int GenerateSubclass (lua_State *L, const std::string &base, const std::string &name)
 Generate a Lua subclass of a native class. More...
 

Private Attributes

Util::OS::path_t basePath
 
Script::RegistryRef requireCache
 
Rulebookrulebook
 

Additional Inherited Members

- Static Protected Member Functions inherited from HoverRace::Script::Env
static Core::Chunk LoadChunkFromFile (const Util::OS::path_t &filename)
 Load a chunk from a file. More...
 

Detailed Description

Limited environment for defining rulebooks.

Author
Michael Imamura

Member Typedef Documentation

Constructor & Destructor Documentation

HoverRace::Client::HoverScript::RulebookEnv::RulebookEnv ( Script::Core scripting,
const Util::OS::path_t basePath,
Rulebook rulebook 
)

Constructor.

The root directory of the rulebook is where the rulebook scripts will be found; a rulebook is not allowed to access any scripts outside of its root directory.

Parameters
scriptingThe scripting context.
basePathThe root directory of the rulebook.
rulebookThe rulebook bound to this environment.
HoverRace::Client::HoverScript::RulebookEnv::~RulebookEnv ( )
virtual

Member Function Documentation

void HoverRace::Client::HoverScript::RulebookEnv::DefineRulebook ( const std::string &  name,
const luabind::object &  defn 
)
void HoverRace::Client::HoverScript::RulebookEnv::DefineRules ( const luabind::object &  rulesObj)
private
int HoverRace::Client::HoverScript::RulebookEnv::GenerateSubclass ( lua_State *  L,
const std::string &  base,
const std::string &  name 
)
staticprivate

Generate a Lua subclass of a native class.

Parameters
LThe Lua state.
baseThe name of the native base class.
nameThe name of the function (in Lua) generating the class, used in error messages.
Returns
The number of return values left on the Lua stack.
void HoverRace::Client::HoverScript::RulebookEnv::InitCFn ( const char *  name,
lua_CFunction  fn 
)
protected

Register a member function in a table.

This is expected to be called from InitEnv() to add global functions to the environment.

The top of the Lua stack must be the destination table.

The function being registered will receive a single upvalue, which is the this pointer.

Parameters
nameThe Lua name of the function.
fnThe function to register.
void HoverRace::Client::HoverScript::RulebookEnv::InitEnv ( )
protectedvirtual

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.

Implements HoverRace::Script::Env.

int HoverRace::Client::HoverScript::RulebookEnv::LPlayer ( lua_State *  L)
static
int HoverRace::Client::HoverScript::RulebookEnv::LRequire ( lua_State *  L)
static
int HoverRace::Client::HoverScript::RulebookEnv::LRulebookStage1 ( lua_State *  L)
static
int HoverRace::Client::HoverScript::RulebookEnv::LRulebookStage2 ( lua_State *  L)
static
int HoverRace::Client::HoverScript::RulebookEnv::LSession ( lua_State *  L)
static
bool HoverRace::Client::HoverScript::RulebookEnv::RunRulebookScript ( )

Run the boot script for a rulebook.

Member Data Documentation

Util::OS::path_t HoverRace::Client::HoverScript::RulebookEnv::basePath
private
Script::RegistryRef HoverRace::Client::HoverScript::RulebookEnv::requireCache
private
Rulebook& HoverRace::Client::HoverScript::RulebookEnv::rulebook
private

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