Diluculum::LuaValue Class Reference

#include <LuaValue.hpp>

List of all members.

Public Member Functions

 LuaValue ()
 Constructs a LuaValue with a nil value.
 LuaValue (bool b)
 Constructs a LuaValue with boolean type and b value.
 LuaValue (float n)
 Constructs a LuaValue with number type and n value.
 LuaValue (double n)
 Constructs a LuaValue with number type and n value.
 LuaValue (long double n)
 Constructs a LuaValue with number type and n value.
 LuaValue (short n)
 Constructs a LuaValue with number type and n value.
 LuaValue (unsigned short n)
 Constructs a LuaValue with number type and n value.
 LuaValue (int n)
 Constructs a LuaValue with number type and n value.
 LuaValue (unsigned n)
 Constructs a LuaValue with number type and n value.
 LuaValue (long n)
 Constructs a LuaValue with number type and n value.
 LuaValue (unsigned long n)
 Constructs a LuaValue with number type and n value.
 LuaValue (const std::string &s)
 Constructs a LuaValue with string type and s value.
 LuaValue (const char *s)
 Constructs a LuaValue with string type and s value.
 LuaValue (const LuaValueMap &t)
 Constructs a LuaValue with table type and t value.
 LuaValue (lua_CFunction f)
 Constructs a LuaValue with function type and f value.
 LuaValue (const LuaUserData &ud)
 Constructs a LuaValue with "user data" type and ud value.
 LuaValue (const LuaValueList &v)
const LuaValueListoperator= (const LuaValueList &rhs)
int type () const
std::string typeName () const
lua_Number asNumber () const
const std::string & asString () const
bool asBoolean () const
LuaValueMap asTable () const
lua_CFunction asFunction () const
const LuaUserDataasUserData () const
LuaUserDataasUserData ()
bool operator< (const LuaValue &rhs) const
bool operator> (const LuaValue &rhs) const
bool operator== (const LuaValue &rhs) const
bool operator!= (const LuaValue &rhs) const
LuaValueoperator[] (const LuaValue &key)
const LuaValueoperator[] (const LuaValue &key) const

Private Attributes

boost::variant< NilType, lua_Number,
std::string, bool, LuaValueMap,
lua_CFunction, LuaUserData
value_
 Stores the value (and the type) stored in this LuaValue.

Classes

class  NilType
 Almost dummy class; simply represents the type of nil. More...


Detailed Description

A class that somewhat mimics a Lua value. Notice that a LuaValue is a C++-side thing. There is absolutely no relationship between a LuaValue and a Lua state. This is particularly important for tables and userdata: in Lua, these things are garbage-collectible objects, and variables are just references to them. In Diluculum, a LuaValue represents the value (hence the name!). So, if a LuaValue holds a table, then it contains a collection of keys and values. Similarly, if it holds a userdata, it actually contains a block of memory with some data.

Definition at line 54 of file LuaValue.hpp.


Constructor & Destructor Documentation

Diluculum::LuaValue::LuaValue  )  [inline]
 

Constructs a LuaValue with a nil value.

Definition at line 58 of file LuaValue.hpp.

Diluculum::LuaValue::LuaValue bool  b  )  [inline]
 

Constructs a LuaValue with boolean type and b value.

Definition at line 61 of file LuaValue.hpp.

Diluculum::LuaValue::LuaValue float  n  )  [inline]
 

Constructs a LuaValue with number type and n value.

Definition at line 66 of file LuaValue.hpp.

Diluculum::LuaValue::LuaValue double  n  )  [inline]
 

Constructs a LuaValue with number type and n value.

Definition at line 71 of file LuaValue.hpp.

Diluculum::LuaValue::LuaValue long double  n  )  [inline]
 

Constructs a LuaValue with number type and n value.

Definition at line 76 of file LuaValue.hpp.

Diluculum::LuaValue::LuaValue short  n  )  [inline]
 

Constructs a LuaValue with number type and n value.

Definition at line 81 of file LuaValue.hpp.

Diluculum::LuaValue::LuaValue unsigned short  n  )  [inline]
 

Constructs a LuaValue with number type and n value.

Definition at line 86 of file LuaValue.hpp.

Diluculum::LuaValue::LuaValue int  n  )  [inline]
 

Constructs a LuaValue with number type and n value.

Definition at line 91 of file LuaValue.hpp.

Diluculum::LuaValue::LuaValue unsigned  n  )  [inline]
 

Constructs a LuaValue with number type and n value.

Definition at line 96 of file LuaValue.hpp.

Diluculum::LuaValue::LuaValue long  n  )  [inline]
 

Constructs a LuaValue with number type and n value.

Definition at line 101 of file LuaValue.hpp.

Diluculum::LuaValue::LuaValue unsigned long  n  )  [inline]
 

Constructs a LuaValue with number type and n value.

Definition at line 106 of file LuaValue.hpp.

Diluculum::LuaValue::LuaValue const std::string &  s  )  [inline]
 

Constructs a LuaValue with string type and s value.

Definition at line 111 of file LuaValue.hpp.

Diluculum::LuaValue::LuaValue const char *  s  )  [inline]
 

Constructs a LuaValue with string type and s value.

Definition at line 116 of file LuaValue.hpp.

Diluculum::LuaValue::LuaValue const LuaValueMap t  )  [inline]
 

Constructs a LuaValue with table type and t value.

Definition at line 121 of file LuaValue.hpp.

Diluculum::LuaValue::LuaValue lua_CFunction  f  )  [inline]
 

Constructs a LuaValue with function type and f value.

Definition at line 126 of file LuaValue.hpp.

Diluculum::LuaValue::LuaValue const LuaUserData ud  )  [inline]
 

Constructs a LuaValue with "user data" type and ud value.

Definition at line 131 of file LuaValue.hpp.

Diluculum::LuaValue::LuaValue const LuaValueList v  ) 
 

Constructs a LuaValue from a LuaValueList. The first value on the list is used to initialize the LuaValue. If the LuaValueList is empty, initializes the constructed LuaValue to Nil.


Member Function Documentation

bool Diluculum::LuaValue::asBoolean  )  const
 

Return the value as a boolean.

Exceptions:
TypeMismatchError If the value is not a boolean (this is a strict check; no type conversion is performed).

lua_CFunction Diluculum::LuaValue::asFunction  )  const
 

Return the value as a function.

Exceptions:
TypeMismatchError If the value is not a function (this is a strict check; no type conversion is performed).

lua_Number Diluculum::LuaValue::asNumber  )  const
 

Return the value as a number.

Exceptions:
TypeMismatchError If the value is not a number (this is a strict check; no type conversion is performed).

const std::string& Diluculum::LuaValue::asString  )  const
 

Return the value as a string.

Exceptions:
TypeMismatchError If the value is not a string (this is a strict check; no type conversion is performed).

LuaValueMap Diluculum::LuaValue::asTable  )  const
 

Returns the value as a table (LuaValueMap).

Note:
Notice that the table is returned by value. You may strongly consider using the subscript operator (that returns a reference) for accessing the values stored in a table-typed LuaValue.
Exceptions:
TypeMismatchError If the value is not a table (this is a strict check; no type conversion is performed).

LuaUserData& Diluculum::LuaValue::asUserData  ) 
 

Return the value as a (full) user data.

Note:
Since this is returned as a non-const reference, the LuaUserData::getData() method can be used to get read/write access to the raw user data.
Exceptions:
TypeMismatchError If the value is not a (full) user data (this is a strict check; no type conversion is performed).

const LuaUserData& Diluculum::LuaValue::asUserData  )  const
 

Return the value as a const (full) user data.

Exceptions:
TypeMismatchError If the value is not a (full) user data (this is a strict check; no type conversion is performed).

bool Diluculum::LuaValue::operator!= const LuaValue rhs  )  const [inline]
 

"Different" operator for LuaValues.

Returns:
true if *this and rhs don't have the same value. false otherwise.

Definition at line 253 of file LuaValue.hpp.

bool Diluculum::LuaValue::operator< const LuaValue rhs  )  const
 

"Less than" operator for LuaValues.

Returns:
The order relationship is quite arbitrary for LuaValues, but this has to be defined in order to LuaValueMap work nicely. Anyway, here are the rules used to determine who is less than who:
  • First, typeName() is called for both LuaValues and they are compared with the usual "less than" operator for strings.
  • If both type names are equal, but something different than "nil" and "table", then the values contained in the LuaValues are compared using the "less than" operator for that type.
  • If both type names are "nil", the function returns false.
  • If both type names are "table", then the number of elements in each table are compared. The shorter table is "less than" the larger table.
  • If both tables have the same size, then each entry is recursively compared (that is, using the rules described here). For each entry, the key is compared first, than the value. This is done until finding something "less than" the other thing.
  • If no differences are found, false is obviously returned.

const LuaValueList& Diluculum::LuaValue::operator= const LuaValueList rhs  ) 
 

Assigns a LuaValueList to a LuaValue. The first value on the list is used to initialize the LuaValue. If the LuaValueList is empty, sets the LuaValue to Nil.

bool Diluculum::LuaValue::operator== const LuaValue rhs  )  const
 

"Equal" operator for LuaValues.

Returns:
true if *this and rhs have the same value. false otherwise.

bool Diluculum::LuaValue::operator> const LuaValue rhs  )  const
 

"Greater than" operator for LuaValues.

Returns:
The rules for determining who is greater than who are similar to the ones described in operator<.

const LuaValue& Diluculum::LuaValue::operator[] const LuaValue key  )  const
 

Returns a const reference to a field of this LuaValue (assuming it is a table). If there is no value associated with the key passed as parameter, returns Nil.

Exceptions:
TypeMismatchError If this LuaValue does not hold a table.

LuaValue& Diluculum::LuaValue::operator[] const LuaValue key  ) 
 

Returns a reference to a field of this LuaValue (assuming it is a table). If there is no value associated with the key passed as parameter, inserts a new value (nil) and returns a reference to it.

Exceptions:
TypeMismatchError If this LuaValue does not hold a table.

int Diluculum::LuaValue::type  )  const
 

Returns one of the LUA_T* constants from lua.h, representing the type stored in this LuaValue.

std::string Diluculum::LuaValue::typeName  )  const
 

Returns the type of this LuaValue as a string, just like the Lua built-in function type().

Returns:
One of the following strings: "nil", "boolean", "number", "string", "table", "function", "userdata".


Member Data Documentation

boost::variant<NilType, lua_Number, std::string, bool, LuaValueMap, lua_CFunction, LuaUserData> Diluculum::LuaValue::value_ [private]
 

Stores the value (and the type) stored in this LuaValue.

Definition at line 277 of file LuaValue.hpp.


The documentation for this class was generated from the following file:
Generated on Tue Feb 6 09:30:26 2007 for Diluculum by  doxygen 1.4.6