Graphite  Version 3
An experimental 3D geometry processing program
OGF::LuaInterpreter Class Reference

The main class that interfaces the Python interpreter with Graphite. More...

#include <OGF/gom/lua/lua_interpreter.h>

Inheritance diagram for OGF::LuaInterpreter:
OGF::Interpreter OGF::Object GEO::Counted

Public Member Functions

 LuaInterpreter ()
 LuaInterpreter constructor.
 
 ~LuaInterpreter () override
 LuaInterpreter destructor.
 
void reset () override
 Clears all variables, restarts from initial state. More...
 
bool execute (const std::string &command, bool save_in_history, bool log) override
 Executes a single line of code in the interpreted language. More...
 
bool execute_file (const std::string &file_name) override
 Executes commands from a given file. More...
 
Any resolve (const std::string &id, bool quiet=true) const override
 Finds a variable by id. More...
 
void bind (const std::string &id, const Any &value) override
 Binds a value to a variable. More...
 
Any eval (const std::string &expression, bool quiet=true) const override
 Evaluates a string with an expression. More...
 
lua_State * lua_state ()
 Gets the LUA state. More...
 
void list_names (std::vector< std::string > &names) const override
 Lists the variable names in this Scope. More...
 
- Public Member Functions inherited from OGF::Interpreter
 Interpreter ()
 Interpreter constructor.
 
void inspect_meta_type (MetaType *meta_type)
 Outputs to the logger the methods, slots, properties of a given MetaClass. More...
 
void list_classes ()
 Outputs to the logger the names of all classes registered to GOM.
 
void bind_object (const std::string &id, Object *object)
 Binds an object to a variable. More...
 
Objectresolve_object (const std::string &id, bool quiet=true) const
 Finds an objet by id. More...
 
Objectresolve_object_by_global_id (const std::string &id, bool quiet=true) const
 Finds an objet by global id. More...
 
Objecteval_object (const std::string &expression, bool quiet=true) const
 Evaluates a string with an expression. More...
 
std::string eval_string (const std::string &expression, bool quiet=true) const
 Evaluates a string with an expression. More...
 
virtual MetaTyperesolve_meta_type (const std::string &type_name) const
 Finds a MetaType by name. More...
 
virtual bool bind_meta_type (MetaType *mtype)
 Binds a MetaType. More...
 
virtual Objectcreate (const ArgList &args)
 Creates an object. More...
 
virtual std::string get_environment_value (const std::string &name)
 Gets the value of a Geogram environment value. More...
 
virtual void set_environment_value (const std::string &name, const std::string &value)
 Sets the value of an environment variable. More...
 
virtual void out (const std::string &message, const std::string &tag="GOM")
 Displays a message in the terminal or console. More...
 
virtual void err (const std::string &message, const std::string &tag="GOM")
 Displays an error message in the terminal or console. More...
 
virtual void warn (const std::string &message, const std::string &tag="GOM")
 Displays a warning message in the terminal or console. More...
 
virtual void status (const std::string &message)
 Displays a status message. More...
 
virtual void append_dynamic_libraries_path (const std::string &path)
 Adds a path where dynamic libraries can be loaded. More...
 
virtual bool load_module (const std::string &module_name)
 Loads a plug-in. More...
 
virtual Connectionconnect (Request *from, Callable *to)
 Connects a signal to a callable. More...
 
Interpreterinterpreter (const std::string &language)
 Gets an interpreter for a given language. More...
 
Interpreterinterpreter_by_file_extension (const std::string &extension)
 Gets an interpreter for a given language by file extension. More...
 
void search (const std::string &needle, const std::string &path="")
 Displays the names of all objects that contain a substring. More...
 
const std::string & get_language () const
 Gets the name of the interpreted language. More...
 
const std::string & get_filename_extension () const
 Gets the filename extensions for the interpreted language. More...
 
Scopeget_globals () const
 Gets the Scope with the global variables. More...
 
Scopeget_meta_types () const
 Gets the Scope with the meta types. More...
 
virtual ~Interpreter ()
 Interpreter destructor.
 
Objectcreate (const std::string &classname, const ArgList &args)
 Creates an object from a classname and arguments list. More...
 
virtual void automatic_completion (const std::string &line, index_t startw, index_t endw, const std::string &cmpword, std::vector< std::string > &matches)
 Gets the possible automatic completions from a partial command entered by the user in the command line. More...
 
virtual void save_history (const std::string &file_name) const
 Saves the history to a file. More...
 
virtual void clear_history ()
 Clears the history.
 
void add_to_history (const std::string &command)
 Adds a command line to the history. More...
 
size_t history_size () const
 Gets the size of the history. More...
 
std::string history_line (unsigned int l) const
 Gets one of the commands in the history by line index. More...
 
- Public Member Functions inherited from OGF::Object
 Object (bool transient=false)
 Object constructor. More...
 
virtual ~Object ()
 Object destructor.
 
virtual MetaClassmeta_class () const
 Gets the meta class. More...
 
virtual void set_meta_class (MetaClass *mclass)
 Sets the meta class. More...
 
unsigned int id () const
 Gets the identifier of this object. More...
 
std::string string_id () const
 Gets the unique string identifier. More...
 
bool has_method (const std::string &method_name) const
 Tests whether a method is defined. More...
 
virtual bool invoke_method (const std::string &method_name, const ArgList &args, Any &ret_val)
 Invokes a method by method name and argument list, and gets the return value. More...
 
bool invoke_method (const std::string &method_name, const ArgList &args)
 Invokes a method by method name and argument list. More...
 
bool invoke_method (const std::string &method_name)
 Invokes a method by method name. More...
 
bool has_property (const std::string &prop_name) const
 Tests whether a property is defined. More...
 
virtual bool get_property (const std::string &prop_name, std::string &prop_value) const
 Gets a property. More...
 
virtual Connectionconnect_signal_to_slot (const std::string &signal_name, Object *to, const std::string &slot_name)
 Connects a signal with a slot of another object. More...
 
virtual void add_connection (Connection *connection)
 Adds a connection to this object. More...
 
virtual void remove_connection (Connection *connection)
 Removes a connection to this object. More...
 
virtual void get_element (index_t i, Any &value) const
 Gets an element by index. More...
 
virtual void set_element (index_t i, const Any &value)
 Sets an element by index. More...
 
bool get_signals_enabled () const
 Tests wheter signals are enabled. More...
 
void set_signals_enabled (bool value)
 Enables or disables signals. More...
 
bool get_slots_enabled () const
 Tests wheter slots are enabled. More...
 
void set_slots_enabled (bool value)
 Enables or disables slots. More...
 
MetaClassget_meta_class () const
 Gets the meta class. More...
 
std::string get_string_id () const
 Gets the unique string identifier. More...
 
virtual std::string get_doc () const
 Gets the documentation. More...
 
virtual Sign compare (const Object *other) const
 Compares this object with another one. More...
 
virtual bool is_a (const MetaType *type) const
 Tests whether this object inherits a given type. More...
 
void disconnect ()
 Removes all connections from signals of this objects. More...
 
void enable_signals ()
 Enables signals.
 
void disable_signals ()
 Disables signals.
 
void enable_slots ()
 Enables slots.
 
void disable_slots ()
 Disables slots.
 
void set_properties (const ArgList &args)
 Sets several properties in a single call. More...
 
virtual bool set_property (const std::string &name, const std::string &value)
 Sets an individual property. More...
 
void help () const
 Displays some help about this object. More...
 
virtual bool set_property (const std::string &name, const Any &value)
 Sets an individual property. More...
 
virtual bool get_property (const std::string &prop_name, Any &prop_value) const
 Gets a property. More...
 
- Public Member Functions inherited from GEO::Counted
void ref () const
 Increments the reference count. More...
 
void unref () const
 Decrements the reference count. More...
 
bool is_shared () const
 Check if the object is shared. More...
 
int nb_refs () const
 Gets the number of references that point to this object. More...
 

Static Public Member Functions

static void display_error_message (const std::string &msg)
 Displays a Lua error message. More...
 
- Static Public Member Functions inherited from OGF::Interpreter
static Interpreterdefault_interpreter ()
 Gets the default interpreter. More...
 
static Interpreterinstance_by_language (const std::string &language)
 Gets the instance of the interpreter that interprets a given language. More...
 
static Interpreterinstance_by_file_extension (const std::string &extension)
 Gets the instance of the interpreter by file extension. More...
 
static void initialize (Interpreter *instance, const std::string &language, const std::string &extension)
 Initializes the interpreter subsystem, and defines the interpreter to be used. More...
 
static void terminate (const std::string &language, const std::string &extension)
 Terminates an interpreter and removes a given language from the list of interpreters. More...
 
static void terminate ()
 Terminates the interpreter subsystem, and deallocates the interpreter. More...
 
- Static Public Member Functions inherited from OGF::Object
static Objectid_to_object (unsigned int id)
 Gets an object from a unique object id. More...
 
- Static Public Member Functions inherited from GEO::Counted
static void ref (const Counted *counted)
 Increments the reference count. More...
 
static void unref (const Counted *counted)
 Decrements the reference count. More...
 

Protected Member Functions

virtual void adjust_lua_state ()
 Adjusts LUA state to recover from errors. More...
 
void get_keys (const std::string &context, std::vector< std::string > &keys) override
 Gets all possible keys in a certain context. More...
 
std::string name_value_pair_call (const std::string &args) const override
 Transforms a list of name-value pairs arguments. More...
 
- Protected Member Functions inherited from OGF::Interpreter
void filename_completion (const std::string &prefix, std::vector< std::string > &completions)
 Gets all possible filenames starting from a certain prefix. More...
 
void filter_completion_candidates (const std::string &prefix, std::vector< std::string > &completions)
 Keeps in a list of completion only those that start with a given prefix. More...
 
virtual void get_keys (Any &context, std::vector< std::string > &keys)
 Gets all possible keys in a certain context. More...
 
void inspect_method (Object *object, MetaMethod *mmethod)
 Displays the prototype of a given method of an object. More...
 
void inspect_meta_class (Object *object, MetaClass *mclass)
 Displays a meta class. More...
 
void inspect_meta_method (MetaMethod *mmethod)
 Outputs to the logger the signature of a method. More...
 
void set_language (const std::string &language)
 Sets the name of the interpreted language. More...
 
void set_filename_extension (const std::string &extension)
 Sets the filename extensions for the interpreted language. More...
 
virtual std::string stringify (const std::string &str) const
 Transforms a string into a string constant in the interpreted language. More...
 
- Protected Member Functions inherited from OGF::Object
virtual bool emit_signal (const std::string &signal_name, const ArgList &args, bool called_from_slot=false)
 Emits a signal and calls the slots it is connected to. More...
 
- Protected Member Functions inherited from GEO::Counted
 Counted ()
 Creates a reference counted object. More...
 
virtual ~Counted ()
 Destroys a reference counted object. More...
 

Additional Inherited Members

- Public Attributes inherited from OGF::Interpreter
 __pad0__: void inspect(Object* object)
 
 __pad1__: virtual std::string get_history() const
 
- Public Attributes inherited from OGF::Object
 __pad0__: virtual index_t get_nb_elements() const
 
 __pad1__: bool equals(const Object* other) const
 
- Protected Attributes inherited from OGF::Interpreter
std::vector< std::string > history_
 
std::string language_
 
std::string extension_
 

Detailed Description

The main class that interfaces the Python interpreter with Graphite.

Definition at line 94 of file lua_interpreter.h.

Member Function Documentation

◆ adjust_lua_state()

virtual void OGF::LuaInterpreter::adjust_lua_state ( )
protectedvirtual

Adjusts LUA state to recover from errors.

Base class implementation does nothing. It can be overriden to recover from errors. For instance, it can call adjust_lua_glup_state() if GLUP bindings are activated.

◆ bind()

void OGF::LuaInterpreter::bind ( const std::string &  id,
const Any value 
)
overridevirtual

Binds a value to a variable.

The variable is then visible from the interpreter in the global scope.

Parameters
[in]idthe name of the variable.
[in]valuethe value of the variable to be bound.

Implements OGF::Interpreter.

◆ display_error_message()

static void OGF::LuaInterpreter::display_error_message ( const std::string &  msg)
static

Displays a Lua error message.

Removes the repetition of the source-code between square brackets which is of little use to tue user.

Parameters
[in]msgthe error message to display.

◆ eval()

Any OGF::LuaInterpreter::eval ( const std::string &  expression,
bool  quiet = true 
) const
overridevirtual

Evaluates a string with an expression.

Parameters
[in]expressiona string with an expression.
[in]quietif true, do not display error messages.
Returns
an Any with the computed value.

Reimplemented from OGF::Interpreter.

◆ execute()

bool OGF::LuaInterpreter::execute ( const std::string &  command,
bool  save_in_history,
bool  log 
)
overridevirtual

Executes a single line of code in the interpreted language.

Parameters
[in]commandthe line of code
[in]save_in_historytrue if the command should be saved in the history
[in]logtrue if the command should be displayed to the logging console
Return values
trueif the command could be sucessfully executed
falseotherwise

Implements OGF::Interpreter.

◆ execute_file()

bool OGF::LuaInterpreter::execute_file ( const std::string &  file_name)
overridevirtual

Executes commands from a given file.

Parameters
[in]file_namename of the file that contains the commands to be executed
Return values
trueif the file could be sucessfully executed
falseotherwise

Reimplemented from OGF::Interpreter.

◆ get_keys()

void OGF::LuaInterpreter::get_keys ( const std::string &  context,
std::vector< std::string > &  keys 
)
overrideprotectedvirtual

Gets all possible keys in a certain context.

Parameters
[in]contextthe name of a variable.
[out]keysthe name of all the data members and function members of the variable.

Reimplemented from OGF::Interpreter.

◆ list_names()

void OGF::LuaInterpreter::list_names ( std::vector< std::string > &  names) const
overridevirtual

Lists the variable names in this Scope.

Parameters
[out]namesa vector of strings with the names of the variables.

Reimplemented from OGF::Interpreter.

◆ lua_state()

lua_State* OGF::LuaInterpreter::lua_state ( )
inline

Gets the LUA state.

Returns
a pointer to the LUA state.

Definition at line 144 of file lua_interpreter.h.

◆ name_value_pair_call()

std::string OGF::LuaInterpreter::name_value_pair_call ( const std::string &  args) const
overrideprotectedvirtual

Transforms a list of name-value pairs arguments.

Some interpreters (e.g., Lua) need special syntax for name-value pair calls. Default implementation returns the input string.

Parameters
[in]argsa set of comma-separated name-value pairs.
Returns
the input args in a form that can be understood as name- value pairs by the target language.

Reimplemented from OGF::Interpreter.

◆ reset()

void OGF::LuaInterpreter::reset ( )
overridevirtual

Clears all variables, restarts from initial state.

Implements OGF::Interpreter.

◆ resolve()

Any OGF::LuaInterpreter::resolve ( const std::string &  id,
bool  quiet = true 
) const
overridevirtual

Finds a variable by id.

Parameters
[in]idthe id, can be either a previously bound id defined in the interpreter, or an id of the form "@ClassName::#instance", where ClassName is the name of a class registered to GOM, and instance an integer that refers to a specific instance of that class (the latter form of ids is used by the VCR system for recording events received by the GUI widgets).
[in]quietif true, do not display error messages.
Returns
an any with the variable attached to id in the current Scope, or nil if there is no such a variable.

Reimplemented from OGF::Interpreter.


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