Graphite  Version 3
An experimental 3D geometry processing program
lua_interpreter.h
Go to the documentation of this file.
1 /*
2  * GXML/Graphite: Geometry and Graphics Programming Library + Utilities
3  * Copyright (C) 2000 Bruno Levy
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  * If you modify this software, you should include a notice giving the
20  * name of the person performing the modification, the date of modification,
21  * and the reason for such modification.
22  *
23  * Contact: Bruno Levy
24  *
25  * levy@loria.fr
26  *
27  * ISA Project
28  * LORIA, INRIA Lorraine,
29  * Campus Scientifique, BP 239
30  * 54506 VANDOEUVRE LES NANCY CEDEX
31  * FRANCE
32  *
33  * Note that the GNU General Public License does not permit incorporating
34  * the Software into proprietary programs.
35  */
36 
37 #ifndef H_OGF_GOM_LUA_INTERPRETER_H
38 #define H_OGF_GOM_LUA_INTERPRETER_H
39 
40 #include <OGF/gom/common/common.h>
42 #include <OGF/gom/types/callable.h>
43 
44 struct lua_State;
45 
51 namespace OGF {
52 
53  /*****************************************************************/
54 
58  gom_class GOM_API LuaCallable : public Callable {
59  public:
66  LuaCallable(lua_State* L, int target_index);
67 
71  bool invoke(const ArgList& args, Any& ret_val) override;
72 
76  ~LuaCallable() override;
77 
78  private:
79  index_t instance_id_;
80  lua_State* lua_state_;
81  Interpreter_var interpreter_; // Keeps refcount so that Lua interp
82  // is not destroyed before the last
83  // Callable
84  static index_t current_instance_id_;
85  };
86 
87 
88  /*****************************************************************/
89 
94  gom_class GOM_API LuaInterpreter : public Interpreter {
95  public:
100 
104  ~LuaInterpreter() override;
105 
109  void reset() override;
110 
114  bool execute(
115  const std::string& command, bool save_in_history, bool log
116  ) override;
117 
121  bool execute_file(const std::string& file_name) override;
122 
126  Any resolve(const std::string& id, bool quiet=true) const override;
127 
131  void bind(const std::string& id, const Any& value) override;
132 
137  const std::string& expression, bool quiet=true
138  ) const override;
139 
144  lua_State* lua_state() {
145  return lua_state_;
146  }
147 
154  static void display_error_message(const std::string& msg);
155 
161  void list_names(std::vector<std::string>& names) const override;
162 
163  protected:
164 
172  virtual void adjust_lua_state();
173 
177  void get_keys(
178  const std::string& context, std::vector<std::string>& keys
179  ) override;
180 
184  std::string name_value_pair_call(
185  const std::string& args
186  ) const override;
187 
188 
189  private:
190  lua_State* lua_state_;
191  };
192 
193 }
194 
195 #endif
A class that stores a variable of arbitrary type.
Definition: any.h:62
Represents a list of name-value pairs.
Definition: arg_list.h:65
A Callable object.
Definition: callable.h:50
Abstract base class for the GOM interpreter.
Definition: interpreter.h:222
GOM wrapper around a LUA function.
~LuaCallable() override
LuaCallable destructor.
bool invoke(const ArgList &args, Any &ret_val) override
Invokes a method by method name.
LuaCallable(lua_State *L, int target_index)
LuaCallable constructor.
The main class that interfaces the Python interpreter with Graphite.
lua_State * lua_state()
Gets the LUA state.
void get_keys(const std::string &context, std::vector< std::string > &keys) override
Gets all possible keys in a certain context.
~LuaInterpreter() override
LuaInterpreter destructor.
bool execute(const std::string &command, bool save_in_history, bool log) override
Executes a single line of code in the interpreted language.
std::string name_value_pair_call(const std::string &args) const override
Transforms a list of name-value pairs arguments.
void reset() override
Clears all variables, restarts from initial state.
LuaInterpreter()
LuaInterpreter constructor.
void bind(const std::string &id, const Any &value) override
Binds a value to a variable.
Any resolve(const std::string &id, bool quiet=true) const override
Finds a variable by id.
virtual void adjust_lua_state()
Adjusts LUA state to recover from errors.
bool execute_file(const std::string &file_name) override
Executes commands from a given file.
Any eval(const std::string &expression, bool quiet=true) const override
Evaluates a string with an expression.
void list_names(std::vector< std::string > &names) const override
Lists the variable names in this Scope.
static void display_error_message(const std::string &msg)
Displays a Lua error message.
The abstract base class for the GOM interpreter.
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Global Graphite namespace.
Definition: common.h:76
Definitions common to all include files in the gom library.