1 #ifndef LUABIND_OBJECT_H 2 #define LUABIND_OBJECT_H 8 #include <blitz/array.h> 49 const std::string& Vname,
87 : ls(Ls), obj(Ls->lua_state(), V) {}
93 : ls(V.lua_state()), obj(V.object()) {}
97 void print(std::ostream& Os)
const { Os <<
"LuabindObject";}
104 static std::vector<boost::shared_ptr<BridgeLuabindAndGenericBase> >
112 static std::vector<boost::shared_ptr<BridgeLuabindAndGenericBase> >
128 { luabind::object r = obj[Vname];
return LuabindObject(r, ls);}
131 { luabind::object r = obj[Vidx];
return LuabindObject(r, ls);}
141 return luabind::object_cast<T>(obj);
142 }
catch(std::exception eoriginal) {
144 e <<
"Error converting lua value to\n" 145 <<
"Requested type: " <<
typeid(T).name() <<
"\n";
147 e <<
"Source object is nil";
149 e <<
"Source object is of type: " <<
typeid(obj).name();
163 return value<boost::shared_ptr<T> >();
172 {
return luabind::object_cast_nothrow<T>(obj) != boost::none; }
182 return is_type<boost::shared_ptr<T> >();
189 template<
class T>
void set_value(
const std::string& Vname,
194 template<
class T,
int D>
void set_value(
const std::string& Vname,
195 const blitz::Array<T, D>& V)
197 obj[Vname] = V.copy();
199 void set_value(
const std::string& Vname,
const std::string& V)
262 bool is_nil()
const {
return luabind::type(obj) == LUA_TNIL; }
263 bool is_boolean()
const {
return luabind::type(obj) == LUA_TBOOLEAN; }
264 bool is_number()
const {
return luabind::type(obj) == LUA_TNUMBER; }
265 bool is_string()
const {
return luabind::type(obj) == LUA_TSTRING; }
266 bool is_table()
const {
return luabind::type(obj) == LUA_TTABLE; }
267 bool is_function()
const {
return luabind::type(obj) == LUA_TFUNCTION; }
276 return lua_rawlen(obj.interpreter(), index);
287 luabind::call_function<luabind::object>(obj), ls);
288 }
catch(
const luabind::error& eoriginal) {
290 e <<
"Lua error: " << lua_tostring(lua_state()->lua_state(), -1) <<
"\n";
291 lua_pop(lua_state()->lua_state(), 1);
301 luabind::call_function<luabind::object>(obj, Arg1),
303 }
catch(
const luabind::error& eoriginal) {
305 e <<
"Lua error: " << lua_tostring(lua_state()->lua_state(), -1) <<
"\n";
306 lua_pop(lua_state()->lua_state(), 1);
310 template<
class T1,
class T2>
316 luabind::call_function<luabind::object>
319 }
catch(
const luabind::error& eoriginal) {
321 e <<
"Lua error: " << lua_tostring(lua_state()->lua_state(), -1) <<
"\n";
322 lua_pop(lua_state()->lua_state(), 1);
326 template<
class T1,
class T2,
class T3>
332 luabind::call_function<luabind::object>
333 (obj, Arg1, Arg2, Arg3),
335 }
catch(
const luabind::error& eoriginal) {
337 e <<
"Lua error: " << lua_tostring(lua_state()->lua_state(), -1) <<
"\n";
338 lua_pop(lua_state()->lua_state(), 1);
342 template<
class T1,
class T2,
class T3,
class T4>
349 luabind::call_function<luabind::object>
350 (obj, Arg1, Arg2, Arg3, Arg4),
352 }
catch(
const luabind::error& eoriginal) {
354 e <<
"Lua error: " << lua_tostring(lua_state()->lua_state(), -1) <<
"\n";
355 lua_pop(lua_state()->lua_state(), 1);
360 template<
class T1,
class T2,
class T3,
class T4,
class T5>
362 const T4& Arg4,
const T5& Arg5)
367 luabind::call_function<luabind::object>
368 (obj, Arg1, Arg2, Arg3, Arg4, Arg5),
370 }
catch(
const luabind::error& eoriginal) {
372 e <<
"Lua error: " << lua_tostring(lua_state()->lua_state(), -1) <<
"\n";
373 lua_pop(lua_state()->lua_state(), 1);
377 template<
class T1,
class T2,
class T3,
class T4,
class T5,
class T6>
379 const T4& Arg4,
const T5& Arg5,
const T6& Arg6)
384 luabind::call_function<luabind::object>
385 (obj, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6),
387 }
catch(
const luabind::error& eoriginal) {
389 e <<
"Lua error: " << lua_tostring(lua_state()->lua_state(), -1) <<
"\n";
390 lua_pop(lua_state()->lua_state(), 1);
394 template<
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
397 const T4& Arg4,
const T5& Arg5,
const T6& Arg6,
403 luabind::call_function<luabind::object>
404 (obj, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7),
406 }
catch(
const luabind::error& eoriginal) {
408 e <<
"Lua error: " << lua_tostring(lua_state()->lua_state(), -1) <<
"\n";
409 lua_pop(lua_state()->lua_state(), 1);
413 template<
class T1,
class T2,
class T3,
class T4,
class T5,
class T6,
416 const T4& Arg4,
const T5& Arg5,
const T6& Arg6,
417 const T7& Arg7,
const T8& Arg8)
422 luabind::call_function<luabind::object>
423 (obj, Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7,
425 }
catch(
const luabind::error& eoriginal) {
427 e <<
"Lua error: " << lua_tostring(lua_state()->lua_state(), -1) <<
"\n";
428 lua_pop(lua_state()->lua_state(), 1);
438 return LuabindObject(luabind::newtable(ls->lua_state()), ls);
447 const luabind::object&
object()
const {
return obj;}
476 bool at_end()
const {
return *
this == luabind::iterator(); }
512 const std::string& Vname,
For use with python, it is useful to map all the LuabindObject that are a class defined in full physi...
BridgeLuabindAndGeneric()
void set_value(const std::string &Vname, const boost::shared_ptr< GenericObject > &V)
Set value as a GenericObject, returning true if this succeeds.
This is a light wrapper around the luabind::iterator.
LuabindObject call(const T1 &Arg1, const T2 &Arg2, const T3 &Arg3, const T4 &Arg4, const T5 &Arg5)
static std::vector< boost::shared_ptr< BridgeLuabindAndGenericBase > > base_bridge
Map used for mapping base classes to and from Lua and GenericObject.
boost::shared_ptr< T > value_ptr() const
Return value of a variable found in this table.
void set_value(const std::string &Vname, double V)
void set_index(int Vidx, const boost::shared_ptr< T > &V)
Set an index.
virtual bool set_index(LuabindObject &Lobj, int Vidx, const boost::shared_ptr< GenericObject > &Obj)=0
Set a value if we can. Return true if we set the value, false otherwise.
bool is_type_ptr() const
Test if value in a table is the given type.
This is the base of the exception hierarchy for Full Physics code.
void set_index(int Vidx, const boost::shared_ptr< GenericObject > &V)
Set value as a GenericObject, returning true if this succeeds.
LuabindObject call(const T1 &Arg1, const T2 &Arg2, const T3 &Arg3, const T4 &Arg4, const T5 &Arg5, const T6 &Arg6)
virtual boost::shared_ptr< GenericObject > value(const LuabindObject &Lobj) const =0
Return a GenericObject if we can convert, or a null pointer if we can't.
virtual boost::shared_ptr< LuabindObject > luabind_object(const boost::shared_ptr< LuaState > &Ls, const boost::shared_ptr< GenericObject > &Obj) const =0
Create a LuabindObject from the given type, or return a null pointer if we can't. ...
void set_value(const std::string &Vname, int V)
This is a light wrapper around the luabind::object.
void set_value(const std::string &Vname, bool V)
void set_index(int Vidx, bool V)
void set_index(int Vidx, const std::string &V)
This is a Mixin for classes that can be printed.
LuabindIterator(const LuabindObject &Lbo, const boost::shared_ptr< LuaState > &Ls)
Constructor.
const boost::shared_ptr< LuaState > & lua_state() const
Lua state pointer.
void set_index(int Vidx, const char *V)
LuabindObject call(const T1 &Arg1, const T2 &Arg2, const T3 &Arg3)
virtual ~BridgeLuabindAndGeneric()
void set_value(const std::string &Vname, const char *V)
void set_value(const std::string &Vname, const boost::shared_ptr< T > &V)
Set a value.
virtual boost::shared_ptr< GenericObject > value(const LuabindObject &Lobj) const
Return a GenericObject if we can convert, or a null pointer if we can't.
LuabindObject call(const T1 &Arg1, const T2 &Arg2, const T3 &Arg3, const T4 &Arg4, const T5 &Arg5, const T6 &Arg6, const T7 &Arg7)
LuabindObject operator[](const std::string &Vname) const
Return a variable found in this table as another LuabindObject.
luabind::object & object()
Underlying object.
void set_value(const std::string &Vname, const LuabindObject &V)
LuabindObject call()
Call a function pointed to by this object.
Instance of BridgeLuabindAndGenericBase for a particular type.
LuabindObject call(const T1 &Arg1, const T2 &Arg2)
bool is_type() const
Test if value in a table is the given type.
LuabindObject(const boost::shared_ptr< LuaState > &Ls, const LuabindObject &V)
LuabindObject get_index(int Vidx) const
void set_index(int Vidx, int V)
void print(std::ostream &Os) const
LuabindObject(const luabind::object &Obj, const boost::shared_ptr< LuaState > &Ls)
Constructor.
virtual boost::shared_ptr< LuabindObject > luabind_object(const boost::shared_ptr< LuaState > &Ls, const boost::shared_ptr< GenericObject > &Obj) const
Create a LuabindObject from the given type, or return a null pointer if we can't. ...
int length(int index=0) const
Return the "length" of the value at the given index using the Lua interpreter method that evaluates a...
static LuabindObject nil(const boost::shared_ptr< LuaState > &Ls)
Return a nil value.
LuabindObject new_table()
Creates a new table object.
virtual bool set_value(LuabindObject &Lobj, const std::string &Vname, const boost::shared_ptr< GenericObject > &Obj)=0
Set a value if we can. Return true if we set the value, false otherwise.
T value() const
Return value of a variable.
Contains classes to abstract away details in various Spurr Radiative Transfer software.
virtual ~BridgeLuabindAndGenericBase()
LuabindObject call(const T1 &Arg1, const T2 &Arg2, const T3 &Arg3, const T4 &Arg4, const T5 &Arg5, const T6 &Arg6, const T7 &Arg7, const T8 &Arg8)
For use with SWIG, it is useful to have a base class that everything can be cast to.
LuabindObject call(const T1 &Arg1, const T2 &Arg2, const T3 &Arg3, const T4 &Arg4)
bool is_nil() const
Test type of an object.
virtual bool set_index(LuabindObject &Lobj, int Vidx, const boost::shared_ptr< GenericObject > &Obj)
Set a value if we can. Return true if we set the value, false otherwise.
static std::vector< boost::shared_ptr< BridgeLuabindAndGenericBase > > derived_bridge
Map used for mapping derived class to and from Lua and GenericObject.
void set_index(int Vidx, const LuabindObject &V)
void set_value(const std::string &Vname, const std::string &V)
void set_index(int Vidx, double V)
const luabind::object & object() const
LuabindObject(const boost::shared_ptr< LuaState > &Ls, const T &V)
Conversion constructor.
LuabindObject call(const T1 &Arg1)
virtual bool set_value(LuabindObject &Lobj, const std::string &Vname, const boost::shared_ptr< GenericObject > &Obj)
Set a value if we can. Return true if we set the value, false otherwise.
void set_value(const std::string &Vname, const blitz::Array< T, D > &V)
LuabindObject key() const