ug4
ug::bridge::lua Namespace Reference

Classes

struct  ConstSmartUserDataWrapper
 
struct  LuaParsing
 
struct  LuaParsing< bool >
 
struct  LuaParsing< const char * >
 
struct  LuaParsing< const std::string & >
 
struct  LuaParsing< const void * >
 
struct  LuaParsing< ConstSmartPtr< void > >
 
struct  LuaParsing< double >
 
struct  LuaParsing< float >
 
struct  LuaParsing< int >
 
struct  LuaParsing< size_t >
 
struct  LuaParsing< SmartPtr< void > >
 
struct  LuaParsing< std::string >
 
struct  LuaParsing< void * >
 
struct  RawUserDataWrapper
 
struct  SmartUserDataWrapper
 
struct  UserDataWrapper
 

Enumerations

enum  UserDataWrapperTypes { RAW_POINTER = 1 , SMART_POINTER = 1 << 1 , IS_CONST = 1 << 2 }
 

Functions

bool CreateBindings_LUA (lua_State *L, Registry &reg)
 creates bindings for ug_interface and a given lua-state. More...
 
static int ExecuteMethod (lua_State *L, const ExportedMethodGroup *methodGrp, UserDataWrapper *self, const ClassNameNode *classNameNode, bool errorOutput)
 
void GetBestMatchingMember (const char *classname, const char *name, std::string &minname, int &mind)
 
void GetBestMatchingMember (const IExportedClass *c, const char *name, std::string &minname, int &mind)
 
std::string GetColonWarning (std::string name)
 
static string GetLuaParametersString (lua_State *L, int offsetToFirstParam=0)
 returns a String describing the parameters on the lua stack ex. "GlobalMultiGridRefiner*, LuaUserNumber2d*, number, string" More...
 
string GetNilWarning (lua_State *L, int offsetToFirstParam)
 
static string GetTypeMismatchString (const ParameterInfo &paramsTemplate, lua_State *L, int offsetToFirstParam, int badParamOneBased)
 
static int LuaConstructor (lua_State *L, IExportedClass *c, const char *groupname=nullptr)
 
static int LuaProxyConstructor (lua_State *L)
 
static int LuaProxyDelete (lua_State *L)
 
static int LuaProxyFunction (lua_State *L)
 
static int LuaProxyGroupConstructor (lua_State *L)
 
static int LuaProxyMethod (lua_State *L)
 
static int LuaProxyRelease (lua_State *L)
 
static int LuaToStringDefault (lua_State *L)
 
static int MetatableIndexer (lua_State *L)
 
std::string ParameterStackString (ParameterStack &s)
 
void PrintLUACallStack ()
 
string UGErrorTraceback (UGError &err)
 
SmartUserDataWrapperCreateNewUserData (lua_State *L, const SmartPtr< void > &ptr, const char *metatableName)
 creates a new UserDataWrapper and associates it with ptr in luas registry More...
 
ConstSmartUserDataWrapperCreateNewUserData (lua_State *L, const ConstSmartPtr< void > &ptr, const char *metatableName)
 creates a new UserDataWrapper and associates it with ptr in luas registry More...
 
RawUserDataWrapperCreateNewUserData (lua_State *L, void *ptr, const char *metatableName, void(*deleteFunc)(const void *), bool is_const)
 creates a new UserDataWrapper and associates it with ptr in luas registry More...
 

Variables

const bool IMLPICIT_SMART_PTR_TO_PTR_CONVERSION = true
 

Enumeration Type Documentation

◆ UserDataWrapperTypes

Enumerator
RAW_POINTER 
SMART_POINTER 
IS_CONST 

Function Documentation

◆ CreateBindings_LUA()

◆ CreateNewUserData() [1/3]

ConstSmartUserDataWrapper * ug::bridge::lua::CreateNewUserData ( lua_State L,
const ConstSmartPtr< void > &  ptr,
const char *  metatableName 
)

creates a new UserDataWrapper and associates it with ptr in luas registry

Creates a new userdata in lua, which encapsulates the given pointer / smart-pointer. It then assigns the specified metatable to the userdata. When the function is done, the userdata is left on luas stack.

References IS_CONST, SMART_POINTER, ug::bridge::lua::ConstSmartUserDataWrapper::smartPtr, and ug::bridge::lua::UserDataWrapper::type.

◆ CreateNewUserData() [2/3]

SmartUserDataWrapper * ug::bridge::lua::CreateNewUserData ( lua_State L,
const SmartPtr< void > &  ptr,
const char *  metatableName 
)

creates a new UserDataWrapper and associates it with ptr in luas registry

Creates a new userdata in lua, which encapsulates the given pointer / smart-pointer. It then assigns the specified metatable to the userdata. When the function is done, the userdata is left on luas stack.

References SMART_POINTER, ug::bridge::lua::SmartUserDataWrapper::smartPtr, and ug::bridge::lua::UserDataWrapper::type.

Referenced by ug::bridge::lua::LuaParsing< const void * >::push(), ug::bridge::lua::LuaParsing< ConstSmartPtr< void > >::push(), ug::bridge::lua::LuaParsing< SmartPtr< void > >::push(), and ug::bridge::lua::LuaParsing< void * >::push().

◆ CreateNewUserData() [3/3]

RawUserDataWrapper * ug::bridge::lua::CreateNewUserData ( lua_State L,
void *  ptr,
const char *  metatableName,
void(*)(const void *)  deleteFunc,
bool  is_const 
)

creates a new UserDataWrapper and associates it with ptr in luas registry

Creates a new userdata in lua, which encapsulates the given pointer / smart-pointer. It then assigns the specified metatable to the userdata. When the function is done, the userdata is left on luas stack.

References ug::bridge::lua::RawUserDataWrapper::deleteFunc, IS_CONST, ug::bridge::lua::RawUserDataWrapper::obj, RAW_POINTER, and ug::bridge::lua::UserDataWrapper::type.

Referenced by LuaConstructor().

◆ ExecuteMethod()

◆ GetBestMatchingMember() [1/2]

void ug::bridge::lua::GetBestMatchingMember ( const char *  classname,
const char *  name,
std::string &  minname,
int &  mind 
)

◆ GetBestMatchingMember() [2/2]

void ug::bridge::lua::GetBestMatchingMember ( const IExportedClass c,
const char *  name,
std::string &  minname,
int &  mind 
)

This function is used if the user enters a member function wrong and returns the best guess what he means. Also searches in base classes.

Parameters
c(in) the class
name(in) the name of the member function we are searching
minname(out) the name of the closest match to name (in Levenshtein-Distance)
mind(out) number of edits needed from name -> minname

References ug::bridge::IExportedClass::class_names(), ug::bridge::Registry::get_class(), ug::bridge::IExportedClass::get_const_method(), ug::bridge::IExportedClass::get_method(), GetBestMatchingMember(), ug::bridge::GetUGRegistry(), ug::LevenshteinDistance(), name, ug::bridge::ExportedFunctionBase::name(), ug::bridge::IExportedClass::num_const_methods(), and ug::bridge::IExportedClass::num_methods().

◆ GetColonWarning()

std::string ug::bridge::lua::GetColonWarning ( std::string  name)

users sometimes use the . operator (like in myObject.the_method(parameter) ), which sometimes print very weird error messages. this function tries to catch some of those errors. NOTE: this function can NOT catch errors like approxSpace.print_statistic() ( note the wrong . )

Parameters
namethe name of the function. will be used to search "."+name in the code.
Returns
error string or ""

References errSymb, ug::script::GetDefaultLuaState(), ug::bridge::GetLuaLine(), and name.

Referenced by LuaProxyMethod().

◆ GetLuaParametersString()

static string ug::bridge::lua::GetLuaParametersString ( lua_State L,
int  offsetToFirstParam = 0 
)
static

returns a String describing the parameters on the lua stack ex. "GlobalMultiGridRefiner*, LuaUserNumber2d*, number, string"

References ug::bridge::GetLuaTypeString().

Referenced by LuaConstructor(), LuaProxyFunction(), and LuaProxyMethod().

◆ GetNilWarning()

string ug::bridge::lua::GetNilWarning ( lua_State L,
int  offsetToFirstParam 
)

if one of the parameters is nil, this returns an error to warn the user about not initialised variables

Parameters
Lthe lua state
offsetToFirstParamoffset to first param
Returns
error string or ""

References errSymb.

Referenced by LuaConstructor(), LuaProxyFunction(), and LuaProxyMethod().

◆ GetTypeMismatchString()

static string ug::bridge::lua::GetTypeMismatchString ( const ParameterInfo paramsTemplate,
lua_State L,
int  offsetToFirstParam,
int  badParamOneBased 
)
static
Returns
String describing the reason why LuaStackToParams failed.
Parameters
paramsTempalte
L
offsetToFirstParam
badParamOneBased: return value as in LuaStackParams
See also
LuaStackToParams

References ug::bridge::GetLuaTypeString(), ParameterToString(), and ug::bridge::ParameterInfo::size().

Referenced by ExecuteMethod(), LuaConstructor(), and LuaProxyFunction().

◆ LuaConstructor()

static int ug::bridge::lua::LuaConstructor ( lua_State L,
IExportedClass c,
const char *  groupname = nullptr 
)
static

◆ LuaProxyConstructor()

static int ug::bridge::lua::LuaProxyConstructor ( lua_State L)
static

creates a object of a class

Parameters
L
Returns
The number of items pushed to the stack (should be one = 1 object).

References LuaConstructor().

Referenced by CreateBindings_LUA().

◆ LuaProxyDelete()

static int ug::bridge::lua::LuaProxyDelete ( lua_State L)
static

◆ LuaProxyFunction()

static int ug::bridge::lua::LuaProxyFunction ( lua_State L)
static

◆ LuaProxyGroupConstructor()

static int ug::bridge::lua::LuaProxyGroupConstructor ( lua_State L)
static

creates the class which is set as default class for the specified group. we assume that the first upvalue is a ClassGroupDesc*

Parameters
L
Returns
The number of items pushed to the stack (should be one = 1 object).

References ug::bridge::ClassGroupDesc::empty(), errSymb, ug::bridge::ClassGroupDesc::get_default_class(), ug::bridge::GetLuaFileAndLine(), LuaConstructor(), ug::bridge::ClassGroupDesc::name(), and UG_LOG.

Referenced by CreateBindings_LUA().

◆ LuaProxyMethod()

static int ug::bridge::lua::LuaProxyMethod ( lua_State L)
static

◆ LuaProxyRelease()

static int ug::bridge::lua::LuaProxyRelease ( lua_State L)
static

Referenced by CreateBindings_LUA().

◆ LuaToStringDefault()

static int ug::bridge::lua::LuaToStringDefault ( lua_State L)
static

a default __tostring method which shows classname: <adress> __tostring is used in all print(object) and tostring(object) calls in LUA

Parameters
L
Returns
nr of parameters (its one string)

References ug::bridge::IExportedClass::name(), ug::bridge::ParamsToLuaStack(), ug::bridge::ParameterStack::push(), and sprintf().

Referenced by CreateBindings_LUA().

◆ MetatableIndexer()

◆ ParameterStackString()

std::string ug::bridge::lua::ParameterStackString ( ParameterStack s)

References boost::get(), and s.

Referenced by ExecuteMethod(), LuaConstructor(), and LuaProxyFunction().

◆ PrintLUACallStack()

void ug::bridge::lua::PrintLUACallStack ( )

prints the LUA Call Stack, i.e. the call stack of functions calls in LUA up to this point, files and filelines.

References ug::bridge::LuaStackTraceString(), s, and UG_LOG.

Referenced by LuaConstructor(), LuaProxyFunction(), and LuaProxyMethod().

◆ UGErrorTraceback()

string ug::bridge::lua::UGErrorTraceback ( UGError err)

Variable Documentation

◆ IMLPICIT_SMART_PTR_TO_PTR_CONVERSION

const bool ug::bridge::lua::IMLPICIT_SMART_PTR_TO_PTR_CONVERSION = true