Chi-Tech
chi::Console Class Reference

#include <chi_console.h>

Data Structures

struct  LuaFunctionRegistryEntry
 
struct  LuaFuncWrapperRegEntry
 

Public Types

using WrapperGetInParamsFunc = chi::InputParameters(*)()
 
using WrapperCallFunc = chi::ParameterBlock(*)(const chi::InputParameters &)
 

Public Member Functions

lua_State *& GetConsoleState ()
 
std::vector< std::string > & GetCommandBuffer ()
 
const std::map< std::string, LuaFunctionRegistryEntry > & GetLuaFunctionRegistry () const
 
const std::map< std::string, LuaFunctionRegistryEntry > & GetFunctionWrapperRegistry () const
 
void RunConsoleLoop (char *fileName=nullptr) const
 
int ExecuteFile (const std::string &fileName, int argc, char **argv) const
 
void PostMPIInfo (int location_id, int number_of_processes) const
 
void FlushConsole ()
 Flushes any commands in the command buffer. More...
 
void DumpRegister () const
 Dumps the object registry to stdout. More...
 
void UpdateConsoleBindings (const chi::RegistryStatuses &old_statuses)
 

Static Public Member Functions

static ConsoleGetInstance () noexcept
 
static char AddFunctionToRegistryGlobalNamespace (const std::string &raw_name_in_lua, lua_CFunction function_ptr)
 Adds a lua_CFunction to the registry. More...
 
static char AddFunctionToRegistryInNamespaceWithName (lua_CFunction function_ptr, const std::string &namespace_name, const std::string &function_name)
 Adds a lua_CFunction to the registry. With namespace-table analogy. More...
 
static char AddLuaConstantToRegistry (const std::string &namespace_name, const std::string &constant_name, const chi_data_types::Varying &value)
 Adds a constant to the lua state. More...
 
static InputParameters DefaultGetInParamsFunc ()
 A default function for returning empty input parameters. More...
 
static char AddWrapperToRegistryInNamespaceWithName (const std::string &namespace_name, const std::string &name_in_lua, WrapperGetInParamsFunc syntax_function, WrapperCallFunc actual_function, bool ignore_null_call_func=false)
 Adds a function wrapper to the lua registry. More...
 
static void SetLuaFuncNamespaceTableStructure (const std::string &full_lua_name, lua_CFunction function_ptr)
 Formats a namespace structure as table. More...
 
static void SetLuaFuncWrapperNamespaceTableStructure (const std::string &full_lua_name)
 Formats a namespace structure as a table, but the last entry is a function call. More...
 
static void SetObjectNamespaceTableStructure (const std::string &full_lua_name)
 Formats a namespace structure as a table, but the last entry contains a "Create" function and a type. More...
 
static void FleshOutLuaTableStructure (const std::vector< std::string > &table_names)
 Makes sure a table structure exists for the list of table names. More...
 
static void SetLuaConstant (const std::string &constant_name, const chi_data_types::Varying &value)
 
static CSTMemory GetMemoryUsage ()
 Get current memory usage. More...
 
static double GetMemoryUsageInMB ()
 Get current memory usage in Megabytes. More...
 
static int LuaWrapperCall (lua_State *L)
 Generic entry point for wrapper calls. More...
 

Private Member Functions

 Console () noexcept
 
void LoadRegisteredLuaItems ()
 

Static Private Member Functions

static void AddFunctionToRegistry (const std::string &name_in_lua, lua_CFunction function_ptr)
 

Private Attributes

lua_State * console_state_
 Pointer to lua console state. More...
 
std::vector< std::string > command_buffer_
 Buffer of commands to execute. More...
 
std::map< std::string, LuaFunctionRegistryEntrylua_function_registry_
 
std::map< std::string, LuaFuncWrapperRegEntryfunction_wrapper_registry_
 
std::map< std::string, chi_data_types::Varyinglua_constants_registry_
 

Static Private Attributes

static Console instance_
 

Friends

class ::Chi
 

Detailed Description

Class for handling the console and scripting.

Definition at line 90 of file chi_console.h.

Member Typedef Documentation

◆ WrapperCallFunc

◆ WrapperGetInParamsFunc

Constructor & Destructor Documentation

◆ Console()

chi::Console::Console ( )
privatenoexcept

Default constructor for the console

Definition at line 19 of file chi_console_constrdestr.cc.

Member Function Documentation

◆ AddFunctionToRegistry()

void chi::Console::AddFunctionToRegistry ( const std::string &  name_in_lua,
lua_CFunction  function_ptr 
)
staticprivate

Basic addition to registry. Used by the other public methods to registry a text-key to a lua function.

Definition at line 66 of file chi_console_utilities.cc.

◆ AddFunctionToRegistryGlobalNamespace()

char chi::Console::AddFunctionToRegistryGlobalNamespace ( const std::string &  raw_name_in_lua,
lua_CFunction  function_ptr 
)
static

Adds a lua_CFunction to the registry.

Adds a lua_CFunction to the registry. The registry of functions gets parsed into the lua console when chi::Initialize is called. This particular function will strip the namespace from the the parameter raw_name_in_lua and cause the function to be registered in the global namespace of the lua console.

Definition at line 95 of file chi_console_utilities.cc.

◆ AddFunctionToRegistryInNamespaceWithName()

char chi::Console::AddFunctionToRegistryInNamespaceWithName ( lua_CFunction  function_ptr,
const std::string &  namespace_name,
const std::string &  function_name 
)
static

Adds a lua_CFunction to the registry. With namespace-table analogy.

Adds a lua_CFunction to the registry. The registry of functions gets parsed into the lua console when chi::Initialize is called. The full path of the function will be derived from namespace_name + "::" + function_name.

Definition at line 112 of file chi_console_utilities.cc.

◆ AddLuaConstantToRegistry()

char chi::Console::AddLuaConstantToRegistry ( const std::string &  namespace_name,
const std::string &  constant_name,
const chi_data_types::Varying value 
)
static

Adds a constant to the lua state.

Adds a constant to the lua state. Prepending the constant within a namespace is optional.

Definition at line 127 of file chi_console_utilities.cc.

◆ AddWrapperToRegistryInNamespaceWithName()

char chi::Console::AddWrapperToRegistryInNamespaceWithName ( const std::string &  namespace_name,
const std::string &  name_in_lua,
WrapperGetInParamsFunc  syntax_function,
WrapperCallFunc  actual_function,
bool  ignore_null_call_func = false 
)
static

Adds a function wrapper to the lua registry.

Wrapper functions operate with input and output parameters, essentially hiding the lua interface.

Definition at line 159 of file chi_console_utilities.cc.

◆ DefaultGetInParamsFunc()

chi::InputParameters chi::Console::DefaultGetInParamsFunc ( )
static

A default function for returning empty input parameters.

Definition at line 151 of file chi_console_utilities.cc.

◆ DumpRegister()

void chi::Console::DumpRegister ( ) const

Dumps the object registry to stdout.

Makes a formatted output, readible by the documentation scripts, of all the lua wrapper functions.

Definition at line 390 of file chi_console_utilities.cc.

◆ ExecuteFile()

int chi::Console::ExecuteFile ( const std::string &  fileName,
int  argc,
char **  argv 
) const

Executes the given file in the Lua engine.

Author
Jan

Definition at line 19 of file chi_console_utilities.cc.

◆ FleshOutLuaTableStructure()

void chi::Console::FleshOutLuaTableStructure ( const std::vector< std::string > &  table_names)
static

Makes sure a table structure exists for the list of table names.

Fleshes out a path in a table tree. For example, given "fee::foo::fah::koo, this routine will make sure that fee.foo.fah.koo is defined as a table tree structure. The routine will create a table structure where one is needed and leave existing ones alone.

At the end of the routine the last table in the structure will be on top of the stack.

Definition at line 305 of file chi_console_utilities.cc.

◆ FlushConsole()

void chi::Console::FlushConsole ( )

Flushes any commands in the command buffer.

This function sends the commands contained in the command_buffer to the lua state from where it is executed. These could be commands passed via the command line or loaded elsewhere.

Definition at line 9 of file chi_console_flushconsole.cc.

◆ GetCommandBuffer()

std::vector< std::string > & chi::Console::GetCommandBuffer ( )
inline

Definition at line 131 of file chi_console.h.

◆ GetConsoleState()

lua_State *& chi::Console::GetConsoleState ( )
inline

Definition at line 130 of file chi_console.h.

◆ GetFunctionWrapperRegistry()

const std::map< std::string, LuaFunctionRegistryEntry > & chi::Console::GetFunctionWrapperRegistry ( ) const
inline

Definition at line 140 of file chi_console.h.

◆ GetInstance()

chi::Console & chi::Console::GetInstance ( )
staticnoexcept

Access to the singleton

Definition at line 11 of file chi_console_constrdestr.cc.

◆ GetLuaFunctionRegistry()

const std::map< std::string, LuaFunctionRegistryEntry > & chi::Console::GetLuaFunctionRegistry ( ) const
inline

Definition at line 134 of file chi_console.h.

◆ GetMemoryUsage()

chi::CSTMemory chi::Console::GetMemoryUsage ( )
static

Get current memory usage.

Gets the current memory usage.

Definition at line 13 of file chi_console_memory.cc.

◆ GetMemoryUsageInMB()

double chi::Console::GetMemoryUsageInMB ( )
static

Get current memory usage in Megabytes.

Gets the current memory usage in megabytes.

Definition at line 60 of file chi_console_memory.cc.

◆ LoadRegisteredLuaItems()

void chi::Console::LoadRegisteredLuaItems ( )
private

Registers all lua items so that they are available in the console.

Definition at line 27 of file chi_console_constrdestr.cc.

◆ LuaWrapperCall()

int chi::Console::LuaWrapperCall ( lua_State *  L)
static

Generic entry point for wrapper calls.

This function expects at least 1 parameter. The first parameter must be a string indicating the registered name of the function wrapper to call. All other parameters will be forwarded to the function wrapper.

Definition at line 14 of file chi_console_fwrapper_call.cc.

◆ PostMPIInfo()

void chi::Console::PostMPIInfo ( int  location_id,
int  number_of_processes 
) const

Pushes location id and number of processes to lua state.

Definition at line 51 of file chi_console_utilities.cc.

◆ RunConsoleLoop()

void chi::Console::RunConsoleLoop ( char *  fileName = nullptr) const

Executes the loop for the console.

Wrapper to an MPI_Bcast call for a single integer broadcast from location 0.

Wrapper to an MPI_Bcast call for an array of characters broadcast from location 0.

Wrapper to an MPI_Bcast call for an array of characters broadcast from location 0. This call is for non-home locations.

Executes a string within the lua-console.

Definition at line 11 of file chi_console_loop.cc.

◆ SetLuaConstant()

void chi::Console::SetLuaConstant ( const std::string &  constant_name,
const chi_data_types::Varying value 
)
static

Sets a lua constant in the lua state.

Definition at line 342 of file chi_console_utilities.cc.

◆ SetLuaFuncNamespaceTableStructure()

void chi::Console::SetLuaFuncNamespaceTableStructure ( const std::string &  full_lua_name,
lua_CFunction  function_ptr 
)
static

Formats a namespace structure as table.

Sets/Forms a lua function in the state using a namespace structure.

Definition at line 194 of file chi_console_utilities.cc.

◆ SetLuaFuncWrapperNamespaceTableStructure()

void chi::Console::SetLuaFuncWrapperNamespaceTableStructure ( const std::string &  full_lua_name)
static

Formats a namespace structure as a table, but the last entry is a function call.

Sets/Forms a table structure that mimics the namespace structure of a string. For example the string "sing::sob::nook::Tigger" will be assigned a table structure sing.sob.nook.Tigger = "sing::sob::nook::Tigger". Then finally assigns lua call to this table.

Lambda for making a chunk

Definition at line 225 of file chi_console_utilities.cc.

◆ SetObjectNamespaceTableStructure()

void chi::Console::SetObjectNamespaceTableStructure ( const std::string &  full_lua_name)
static

Formats a namespace structure as a table, but the last entry contains a "Create" function and a type.

Sets/Forms a table structure that mimics the namespace structure of a string. For example the string "sing::sob::nook::Tigger" will be assigned a table structure sing.sob.nook.Tigger = "sing::sob::nook::Tigger".

Lambda for registering object type and creation function.

Definition at line 268 of file chi_console_utilities.cc.

◆ UpdateConsoleBindings()

void chi::Console::UpdateConsoleBindings ( const chi::RegistryStatuses old_statuses)

Given an old status, will update the bindings for only newly registered items.

Definition at line 416 of file chi_console_utilities.cc.

Friends And Related Function Documentation

◆ ::Chi

friend class ::Chi
friend

Definition at line 124 of file chi_console.h.

Field Documentation

◆ command_buffer_

std::vector<std::string> chi::Console::command_buffer_
private

Buffer of commands to execute.

Definition at line 111 of file chi_console.h.

◆ console_state_

lua_State* chi::Console::console_state_
private

Pointer to lua console state.

Definition at line 109 of file chi_console.h.

◆ function_wrapper_registry_

std::map<std::string, LuaFuncWrapperRegEntry> chi::Console::function_wrapper_registry_
private

Definition at line 116 of file chi_console.h.

◆ instance_

Console chi::Console::instance_
staticprivate

Definition at line 112 of file chi_console.h.

◆ lua_constants_registry_

std::map<std::string, chi_data_types::Varying> chi::Console::lua_constants_registry_
private

Definition at line 118 of file chi_console.h.

◆ lua_function_registry_

std::map<std::string, LuaFunctionRegistryEntry> chi::Console::lua_function_registry_
private

Definition at line 114 of file chi_console.h.


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