ug4
ug::script Namespace Reference

Classes

class  LuaError
 Error class thrown if an error occurs during parsing. More...
 

Enumerations

enum  debug_return {
  DEBUG_EXIT =0 , DEBUG_CONTINUE , DEBUG_NEXT , DEBUG_STEP ,
  DEBUG_FINISH
}
 

Functions

void AddBreakpoint (const char *source, int line)
 
void breakpoint ()
 
void breakpoint_in_script ()
 
void CheckHook ()
 
void DebugBacktrace (int fromLevel)
 lists the function stack in lua More...
 
void DebugDown ()
 move down function stack More...
 
void DebugHold ()
 
void DebugList ()
 lists the current line in the script More...
 
void DebugUp ()
 move down function stack More...
 
void FinalizeLUADebug ()
 Free all memory associated with lua_debug. More...
 
UG_API bool GetAbsoluteUGScriptFilename (const std::string &filename, std::string &absoluteFilename)
 
bool GetAbsoluteUGScriptFilename (const string &filename, string &absoluteFilename)
 
std::string GetAbsoluteUGScriptFilenamePaths ()
 
lua_StateGetDefaultLuaState ()
 returns the default lua state More...
 
int getDepth ()
 
bool GetNormalFilename (const string &filename, string &returnedFilename)
 
static void GetToStringFromStack (lua_State *L, std::stringstream &ss)
 
bool IsLUADebug ()
 
bool LoadUGScript (const char *_filename, bool bDistributedLoad, bool bThrowOnError)
 
UG_API bool LoadUGScript (const char *filename, bool bDistributed)
 loads and parses a file. Several paths are tried if the file is not found. More...
 
bool LoadUGScript_Parallel (const char *filename)
 calls LoadUGScript with bDistributed=true More...
 
bool LoadUGScript_Single (const char *filename)
 calls LoadUGScript with bDistributed=false . Avoid. ( More...
 
void LuaCallHook (lua_State *L, lua_Debug *ar)
 
int luaCallStackError (lua_State *L)
 error function to be used for lua_pcall More...
 
void luaDebug (lua_State *L, const char *source, int line)
 
bool ParseAndExecuteBuffer (const char *buffer, const char *bufferName)
 
void PrintBreakpoints ()
 
void ProfileLUA (bool b)
 
void RegisterDefaultLuaBridge (ug::bridge::Registry *reg, std::string grp="/ug4")
 registers lua only functionality at the registry More...
 
bool RegisterLuaDebug (ug::bridge::Registry &reg)
 
void RegisterStdLUAFunctions (lua_State *L)
 register functions like print and write directly to LUA (not using the ug registry) More...
 
void ReleaseDefaultLuaState ()
 calls lua_close, which calls delete for all lua objects More...
 
int SetDebugShell (debug_return(*s)())
 
void SetLuaDebug (lua_State *L, string id)
 
void SetLuaDebugIDs (lua_State *L)
 
void SetLuaUGArgs (lua_State *L, int argc, char *argv[])
 
int UGAlgebraCompiled (lua_State *L)
 Returns if dimension is compiled into binary. More...
 
int UGDimCompiled (lua_State *L)
 Returns if dimension is compiled into binary. More...
 
int UGGetClassGroup (lua_State *L)
 Returns classgroup of a userdata as string. More...
 
int UGGetClassName (lua_State *L)
 Returns type of a userdata as string. More...
 
int UGGetMetatable (lua_State *L)
 Returns the metatable for the given class. More...
 
int UGIsBaseClass (lua_State *L)
 Returns if a class contains a base class. More...
 
int UGLuaErrLog (lua_State *L)
 UGLuaErrLog. More...
 
int UGLuaPrint (lua_State *L)
 UGLuaPrint. Redirects LUA prints to UG_LOG. More...
 
int UGLuaPrintAllProcs (lua_State *L)
 UGLuaPrint. Redirects LUA prints to UG_LOG. More...
 
int UGLuaWrite (lua_State *L)
 UGLuaWrite. Redirects LUA prints to UG_LOG without adding newline at the end. More...
 
void UpdateDepth ()
 
static void UpdateScriptAfterRegistryChange (ug::bridge::Registry *pReg)
 

Variables

static bool bDebugging = false
 
static bool bProfiling = false
 
static std::map< std::string, std::map< int, bool > > breakpoints
 
int curHookMask = 0
 
static int currentDepth = -1
 
static int debugMode = DEBUG_CONTINUE
 
static ug::bridge::Registryg_pRegistry = NULL
 
static int lastline = -1
 
static std::string lastsource
 
static debug_return(* pDebugShell )() = NULL
 
stack< string > stkPathes
 
static lua_StatetheLuaState = NULL
 

Enumeration Type Documentation

◆ debug_return

enum used to control execution flow in debug mode

Enumerator
DEBUG_EXIT 

exit ug

DEBUG_CONTINUE 

continue execution

DEBUG_NEXT 

go to next line, but do not go deeper in stack

DEBUG_STEP 

go to next line, step into functions (deeper in stack)

DEBUG_FINISH 

continue until we finish current function

Function Documentation

◆ AddBreakpoint()

void ug::script::AddBreakpoint ( const char *  source,
int  line 
)

◆ breakpoint()

◆ breakpoint_in_script()

void ug::script::breakpoint_in_script ( )

◆ CheckHook()

void ug::script::CheckHook ( )

◆ DebugBacktrace()

UG_API void ug::script::DebugBacktrace ( int  fromLevel)

lists the function stack in lua

References ug::bridge::LuaStackTrace().

Referenced by ug::bridge::DebugShell(), and RegisterLuaDebug().

◆ DebugDown()

UG_API void ug::script::DebugDown ( )

move down function stack

References currentDepth, getDepth(), UG_LOG, and UpdateDepth().

Referenced by ug::bridge::DebugShell().

◆ DebugHold()

UG_API void ug::script::DebugHold ( )

◆ DebugList()

UG_API void ug::script::DebugList ( )

lists the current line in the script

References currentDepth, GetDefaultLuaState(), getDepth(), ug::GetFileLines(), lastline, lastsource, and UG_LOG.

Referenced by ug::bridge::DebugShell().

◆ DebugUp()

UG_API void ug::script::DebugUp ( )

move down function stack

References currentDepth, UG_LOG, and UpdateDepth().

Referenced by ug::bridge::DebugShell().

◆ FinalizeLUADebug()

UG_API void ug::script::FinalizeLUADebug ( )

Free all memory associated with lua_debug.

References breakpoints, and lastsource.

Referenced by ReleaseDefaultLuaState().

◆ GetAbsoluteUGScriptFilename() [1/2]

UG_API bool ug::script::GetAbsoluteUGScriptFilename ( const std::string &  filename,
std::string &  absoluteFilename 
)

searches for the filename

  • relative to current script
  • as absolute filename
  • in PathProvider::get_path(SCRIPT_PATH) (ug4/scripts)
  • in PathProvider::get_path(APPS_PATH) (ug4/apps)
  • in PathProvider::get_path(ROOT_PATH) (ug4)
    Parameters
    filenamein: relative filename to paths above. out: absolute filename (if found)
    Returns
    true if found, else false

◆ GetAbsoluteUGScriptFilename() [2/2]

bool ug::script::GetAbsoluteUGScriptFilename ( const string &  filename,
string &  absoluteFilename 
)

say UG4_ROOT is the root path of ug4 (containing ugbase, apps, scripts and so on) This function will search a file (in this order) 1.) relative to the current script path. 2.) as a normal, i.e. absolute or relative to the working directory, filename 3.) relative to SCRIPT_PATH (normally UG4_ROOT/scripts) 4.) relative to APPS_PATH (normally UG4_ROOT/apps) 5.) relative to UG4_ROOT

Parameters
filename
absoluteFilename
Returns
true if a file could be found at one of the locations

References ug::APPS_PATH, GetNormalFilename(), PROFILE_FUNC, ug::ROOT_PATH, and ug::SCRIPT_PATH.

Referenced by AddBreakpoint(), and LoadUGScript().

◆ GetAbsoluteUGScriptFilenamePaths()

std::string ug::script::GetAbsoluteUGScriptFilenamePaths ( )

References ug::APPS_PATH, ug::ROOT_PATH, and ug::SCRIPT_PATH.

Referenced by LoadUGScript().

◆ GetDefaultLuaState()

UG_API lua_State * ug::script::GetDefaultLuaState ( )

returns the default lua state

When called for the first time, or after ReleaseDefaultLuaState, a new state is created and the methods and classes in ugs default registry (ug::bridge::GetUGRegistry) are registered. Furthermore a callback is registered, which registers new methods whenever Registry::registry_changed() is called on the default registry.

References ug::bridge::Registry::add_callback(), ug::bridge::lua::CreateBindings_LUA(), g_pRegistry, ug::bridge::GetUGRegistry(), PROFILE_BEGIN, theLuaState, UG_ASSERT, UGAlgebraCompiled(), UGDimCompiled(), UGGetClassGroup(), UGGetClassName(), UGGetMetatable(), UGIsBaseClass(), and UpdateScriptAfterRegistryChange().

Referenced by breakpoint_in_script(), ug::LuaUserData< TData, dim, TRet >::check_callback_returns(), CheckHook(), ug::CheckLuaCallbackName(), ug::bridge::ClassInstantiations(), ug::LUAParserClass::createVM(), DebugList(), ug::bridge::lua::GetColonWarning(), getDepth(), ug::bridge::GetGlobalFunctionInfo(), ug::bridge::GetGlobalsCompletitions(), ug::bridge::GetLuaGlobals(), ug::bridge::GetLUAScriptFunctionDefined(), ug::bridge::GetMemberFunctionCompletitions(), ug::bridge::GetMemberFunctionInfo(), ug::bridge::GetNamespaceCompletitions(), ug::LUAParserClass::getVar(), ug::LuaFunction< TData, TDataIn >::LuaFunction(), ug::bridge::LuaList_classInstantiations(), ug::bridge::LuaList_luaObjects(), ug::bridge::LuaList_scriptFunctions(), ug::bridge::LuaStackTrace(), ug::bridge::LuaStackTraceString(), ug::LuaUserData< TData, dim, TRet >::LuaUserData(), ug::LuaUserFunction< TData, dim, TDataIn >::LuaUserFunction(), ug::LuaUserNumberNumberFunction::LuaUserNumberNumberFunction(), ug::bridge::LuaWrite(), ug::bridge::LuaWriteCout(), ug::LUAParserClass::parse_luaFunction(), ug::LUAParserClass::parse_luaFunction_StackTop(), ParseAndExecuteBuffer(), ug::bridge::SetLuaNamespace(), ug::bridge::SetLuaNamespaceInTable(), ug_init_luashell(), ug::bridge::UGTypeInfo(), UpdateDepth(), and UpdateScriptAfterRegistryChange().

◆ getDepth()

int ug::script::getDepth ( )

◆ GetNormalFilename()

bool ug::script::GetNormalFilename ( const string &  filename,
string &  returnedFilename 
)
Parameters
filename
returnedFilename
Returns
true if a file can be found at filename

References ug::FileExists().

Referenced by GetAbsoluteUGScriptFilename().

◆ GetToStringFromStack()

static void ug::script::GetToStringFromStack ( lua_State L,
std::stringstream &  ss 
)
static

References s.

Referenced by UGLuaErrLog(), UGLuaPrint(), UGLuaPrintAllProcs(), and UGLuaWrite().

◆ IsLUADebug()

bool ug::script::IsLUADebug ( )

References bProfiling.

Referenced by lua_backtrace().

◆ LoadUGScript() [1/2]

bool ug::script::LoadUGScript ( const char *  _filename,
bool  bDistributedLoad,
bool  bThrowOnError 
)
Parameters
_filenamethe 'relative' script name.
See also
GetAbsoluteUGScriptFilename
Parameters
bDistributedLoadtrue if loading should be done in parallel
bThrowOnErrortrue if errors should be thrown as UGError, else as return false
Returns
true if script could be found and read, false (or UGError) if not

References pcl::AllProcsTrue(), GetAbsoluteUGScriptFilename(), GetAbsoluteUGScriptFilenamePaths(), pcl::NumProcs(), pcl::ParallelReadFile(), ParseAndExecuteBuffer(), ug::PathFromFilename(), pcl::ProcRank(), PROFILE_FUNC, ug::ReadFile(), and UG_THROW.

Referenced by LoadUGScript_Parallel(), and LoadUGScript_Single().

◆ LoadUGScript() [2/2]

UG_API bool ug::script::LoadUGScript ( const char *  filename,
bool  bDistributed 
)

loads and parses a file. Several paths are tried if the file is not found.

Throws an instance of LuaError, if a parse error occurs. This method first tries to load the file specified with filename relative to the path of the currently parsed file (if LoadUGScript is called from within a load-script). If this failed, the file is tried to be loaded with the raw specified filename. If this fails too, the method tries to load the file from ugs scripting directory.

Note that this method pushes the path of the currently parsed script to PathProvider when parsing starts, and pops it when parsing is done.

Parameters
filenameThe filename for the script to be loaded. may be relative to ug4/apps/
bDistributedif true, loads the script on core 0 and distributes the script to all other cores via pcl::broadcast . Use this whenever possible when doing parallel work otherwise this routine can take a long time (ignored if UG_PARALLEL not defined)

◆ LoadUGScript_Parallel()

UG_API bool ug::script::LoadUGScript_Parallel ( const char *  filename)

calls LoadUGScript with bDistributed=true

References LoadUGScript().

Referenced by RegisterDefaultLuaBridge(), and ugshell_main().

◆ LoadUGScript_Single()

UG_API bool ug::script::LoadUGScript_Single ( const char *  filename)

calls LoadUGScript with bDistributed=false . Avoid. (

See also
LoadUGScript)

References LoadUGScript().

Referenced by RegisterDefaultLuaBridge().

◆ LuaCallHook()

void ug::script::LuaCallHook ( lua_State L,
lua_Debug *  ar 
)

◆ luaCallStackError()

int ug::script::luaCallStackError ( lua_State L)

error function to be used for lua_pcall

References ug::bridge::LuaStackTrace(), and UG_LOG.

Referenced by ParseAndExecuteBuffer().

◆ luaDebug()

void ug::script::luaDebug ( lua_State L,
const char *  source,
int  line 
)

◆ ParseAndExecuteBuffer()

UG_API bool ug::script::ParseAndExecuteBuffer ( const char *  buffer,
const char *  bufferName = "buffer" 
)

Parses the content of buffer and executes it in the default lua state

Parameters
bufferthe buffer to be executed
bufferNamename of the buffer (for error messages)
Returns
true on success, otherwise throw(LuaError) Throws an instance of LuaError, if a parse error occurs.

References GetDefaultLuaState(), luaCallStackError(), PROFILE_BEGIN, PROFILE_END_, and PROFILE_FUNC.

Referenced by ug::bridge::DebugShell(), LoadUGScript(), ug::bridge::RunShell(), SetLuaDebug(), SetLuaDebugIDs(), and ugshell_main().

◆ PrintBreakpoints()

void ug::script::PrintBreakpoints ( )

References breakpoints, and UG_LOG.

Referenced by RegisterLuaDebug().

◆ ProfileLUA()

UG_API void ug::script::ProfileLUA ( bool  b)

References bProfiling, CheckHook(), and UG_LOG.

Referenced by RegisterLuaDebug().

◆ RegisterDefaultLuaBridge()

◆ RegisterLuaDebug()

UG_API bool ug::script::RegisterLuaDebug ( ug::bridge::Registry reg)

Register debug/profile functions

Parameters
reg
Returns
true
See also
debug_return

References ug::bridge::Registry::add_function(), AddBreakpoint(), breakpoint_in_script(), DebugBacktrace(), PrintBreakpoints(), and ProfileLUA().

Referenced by RegisterDefaultLuaBridge().

◆ RegisterStdLUAFunctions()

UG_API void ug::script::RegisterStdLUAFunctions ( lua_State L)

register functions like print and write directly to LUA (not using the ug registry)

References UGLuaErrLog(), UGLuaPrint(), UGLuaPrintAllProcs(), and UGLuaWrite().

Referenced by ug_init_luashell().

◆ ReleaseDefaultLuaState()

UG_API void ug::script::ReleaseDefaultLuaState ( )

calls lua_close, which calls delete for all lua objects

Releases the lua-state returned by GetDefaultLuaState().

This method is useful, if you want to restart scripting from scratch.

References FinalizeLUADebug(), and theLuaState.

◆ SetDebugShell()

UG_API int ug::script::SetDebugShell ( debug_return(*)()  s)

function called when a breakpoint is reached

Parameters
sdebug shell function
Returns
0
See also
DebugList, DebugBacktrace, DebugDown, DebugUp

References pDebugShell, and s.

Referenced by ug::bridge::InitShell().

◆ SetLuaDebug()

void ug::script::SetLuaDebug ( lua_State L,
string  id 
)

References name, p, and ParseAndExecuteBuffer().

Referenced by SetLuaDebugIDs().

◆ SetLuaDebugIDs()

UG_API void ug::script::SetLuaDebugIDs ( lua_State L)

References ParseAndExecuteBuffer(), s, and SetLuaDebug().

Referenced by ug_init_luashell().

◆ SetLuaUGArgs()

UG_API void ug::script::SetLuaUGArgs ( lua_State L,
int  argc,
char *  argv[] 
)

create ugargc and ugargv in lua we want to forward argc and argv to the lua-environment. we'll create a table for that.

Parameters
Lthe LUA state
argcthe commandline argc
argvthe commandline argv

Referenced by ug_init_luashell().

◆ UGAlgebraCompiled()

UG_API int ug::script::UGAlgebraCompiled ( lua_State L)

Returns if dimension is compiled into binary.

References name.

Referenced by GetDefaultLuaState().

◆ UGDimCompiled()

UG_API int ug::script::UGDimCompiled ( lua_State L)

Returns if dimension is compiled into binary.

References dim.

Referenced by GetDefaultLuaState().

◆ UGGetClassGroup()

UG_API int ug::script::UGGetClassGroup ( lua_State L)

◆ UGGetClassName()

UG_API int ug::script::UGGetClassName ( lua_State L)

Returns type of a userdata as string.

References ug::bridge::ClassNameNode::name(), and UG_THROW.

Referenced by GetDefaultLuaState().

◆ UGGetMetatable()

UG_API int ug::script::UGGetMetatable ( lua_State L)

Returns the metatable for the given class.

References name.

Referenced by GetDefaultLuaState().

◆ UGIsBaseClass()

UG_API int ug::script::UGIsBaseClass ( lua_State L)

Returns if a class contains a base class.

References ug::bridge::ClassNameTreeContains(), ug::bridge::ClassNameNode::empty(), and UG_THROW.

Referenced by GetDefaultLuaState().

◆ UGLuaErrLog()

int ug::script::UGLuaErrLog ( lua_State L)

◆ UGLuaPrint()

UG_API int ug::script::UGLuaPrint ( lua_State L)

UGLuaPrint. Redirects LUA prints to UG_LOG.

References GetToStringFromStack(), and UG_LOG.

Referenced by RegisterStdLUAFunctions().

◆ UGLuaPrintAllProcs()

int ug::script::UGLuaPrintAllProcs ( lua_State L)

UGLuaPrint. Redirects LUA prints to UG_LOG.

UGLuaPrintAllProcs. Redirects LUA prints to UG_LOG_ALL_PROCS.

References GetToStringFromStack(), and UG_LOG_ALL_PROCS.

Referenced by RegisterStdLUAFunctions().

◆ UGLuaWrite()

UG_API int ug::script::UGLuaWrite ( lua_State L)

UGLuaWrite. Redirects LUA prints to UG_LOG without adding newline at the end.

UGLuaWrite. prints LUA output to UG_LOG without adding std::endl automatically.

References ug::LogAssistant::flush(), ug::GetLogAssistant(), GetToStringFromStack(), and UG_LOG.

Referenced by RegisterStdLUAFunctions().

◆ UpdateDepth()

void ug::script::UpdateDepth ( )

◆ UpdateScriptAfterRegistryChange()

static void ug::script::UpdateScriptAfterRegistryChange ( ug::bridge::Registry pReg)
static

Variable Documentation

◆ bDebugging

bool ug::script::bDebugging = false
static

◆ bProfiling

bool ug::script::bProfiling = false
static

◆ breakpoints

std::map<std::string, std::map<int, bool> > ug::script::breakpoints
static

◆ curHookMask

int ug::script::curHookMask = 0

Referenced by CheckHook().

◆ currentDepth

int ug::script::currentDepth = -1
static

◆ debugMode

int ug::script::debugMode = DEBUG_CONTINUE
static

Referenced by breakpoint(), DebugHold(), and luaDebug().

◆ g_pRegistry

ug::bridge::Registry* ug::script::g_pRegistry = NULL
static

◆ lastline

int ug::script::lastline = -1
static

◆ lastsource

std::string ug::script::lastsource
static

◆ pDebugShell

debug_return(* ug::script::pDebugShell) () ( ) = NULL
static

◆ stkPathes

stack<string> ug::script::stkPathes
extern

◆ theLuaState

lua_State* ug::script::theLuaState = NULL
static