Diluculum::LuaVariable Class Reference

#include <LuaVariable.hpp>

List of all members.

Public Types

typedef std::vector< LuaValueKeyList
 A sequence of keys, used to access nested tables.

Public Member Functions

const LuaValueoperator= (const LuaValue &rhs)
LuaValue value () const
LuaVariable operator[] (const LuaValue &key) const
LuaValueList operator() (const LuaValueList &params)
LuaValueList operator() ()
LuaValueList operator() (const LuaValue &param)
LuaValueList operator() (const LuaValue &param1, const LuaValue &param2)
LuaValueList operator() (const LuaValue &param1, const LuaValue &param2, const LuaValue &param3)
LuaValueList operator() (const LuaValue &param1, const LuaValue &param2, const LuaValue &param3, const LuaValue &param4)
LuaValueList operator() (const LuaValue &param1, const LuaValue &param2, const LuaValue &param3, const LuaValue &param4, const LuaValue &param5)
bool operator== (const LuaValue &rhs) const
bool operator== (const LuaVariable &rhs) const
bool operator!= (const LuaVariable &rhs) const
const KeyListgetKeys () const
void pushLastTable ()
lua_State * getState ()

Private Member Functions

 LuaVariable (lua_State *state, const LuaValue &key, const KeyList &predKeys=KeyList())
void pushTheReferencedValue () const

Private Attributes

lua_State * state_
 The Lua state in which this LuaVariable lives.
KeyList keys_

Friends

class LuaState


Detailed Description

A variable living in a Lua state. Notice the crucial difference: unlike a LuaValue, a LuaVariable necessarily has a real counterpart in a Lua state. Thus, when something is assigned to a LuaVariable, the value of the corresponding variable in the Lua state is changed, too.

LuaVariables cannot be directly constructed. They are designed to be returned by LuaState's subscript operator.

Definition at line 43 of file LuaVariable.hpp.


Member Typedef Documentation

typedef std::vector<LuaValue> Diluculum::LuaVariable::KeyList
 

A sequence of keys, used to access nested tables.

Definition at line 247 of file LuaVariable.hpp.


Constructor & Destructor Documentation

Diluculum::LuaVariable::LuaVariable lua_State *  state,
const LuaValue key,
const KeyList predKeys = KeyList()
[private]
 

Constructs a LuaVariable.

Note:
This is private because no one is expected to construct a LuaVariable directly. For Diluculum users, the only allowed way to create a new LuaVariable is by using LuaState's subscript operator.
Parameters:
state The lua_State* in which the variable represented by this LuaVariable resides.
key The "key" used to access the variable represented by this LuaVariable. This can be variable name (for the case of a global variable) or a "real" key (when it is a field in a possibly nested table).
predKeys The sequence of keys used to access the table that contains the variable represented by this LuaVariable. For a global variable, this list will be empty. For a variable stored in a possibly nested table, the list can be arbitrarily long.


Member Function Documentation

const KeyList& Diluculum::LuaVariable::getKeys  )  const [inline]
 

Returns the sequence of keys used to reach this variable.

Note:
This method exists mostly to allow a nicer implementation of other Diluculum features. Users aren't expected to call this.

Definition at line 253 of file LuaVariable.hpp.

References keys_.

lua_State* Diluculum::LuaVariable::getState  )  [inline]
 

Returns the LuaState in which this LuaVariable lives.

Note:
This method exists mostly to allow a nicer implementation of other Diluculum features. Users aren't expected to call this.

Definition at line 271 of file LuaVariable.hpp.

References state_.

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

Checks whether this LuaVariable refers to a different variable than rhs.

Parameters:
rhs The variable against which the comparison will be done.
Returns:
false if both involved LuaVariables refer to the same variable. true otherwise.

Definition at line 243 of file LuaVariable.hpp.

References keys_, and state_.

LuaValueList Diluculum::LuaVariable::operator() const LuaValue param1,
const LuaValue param2,
const LuaValue param3,
const LuaValue param4,
const LuaValue param5
 

Assuming that this LuaVariable holds a function, calls this function and returns its return values. Both "pure" Lua functions and functions written in C/C++ and "exported" to Lua are supported.

Parameters:
param1 The first parameter to be passed to the function being called
param2 The second parameter to be passed to the function being called
param3 The third parameter to be passed to the function being called
param4 The fourth parameter to be passed to the function being called
param5 The fifth parameter to be passed to the function being called
Returns:
All the values returned by the called function. The first return value at index 0, the second at index 1 and so on.
Exceptions:
TypeMismatchError If this LuaVariable tries to subscript something that is not a table.
LuaRunTimeError If something bad happens while executing the function.

LuaValueList Diluculum::LuaVariable::operator() const LuaValue param1,
const LuaValue param2,
const LuaValue param3,
const LuaValue param4
 

Assuming that this LuaVariable holds a function, calls this function and returns its return values. Both "pure" Lua functions and functions written in C/C++ and "exported" to Lua are supported.

Parameters:
param1 The first parameter to be passed to the function being called
param2 The second parameter to be passed to the function being called
param3 The third parameter to be passed to the function being called
param4 The fourth parameter to be passed to the function being called
Returns:
All the values returned by the called function. The first return value at index 0, the second at index 1 and so on.
Exceptions:
TypeMismatchError If this LuaVariable tries to subscript something that is not a table.
LuaRunTimeError If something bad happens while executing the function.

LuaValueList Diluculum::LuaVariable::operator() const LuaValue param1,
const LuaValue param2,
const LuaValue param3
 

Assuming that this LuaVariable holds a function, calls this function and returns its return values. Both "pure" Lua functions and functions written in C/C++ and "exported" to Lua are supported.

Parameters:
param1 The first parameter to be passed to the function being called
param2 The second parameter to be passed to the function being called
param3 The third parameter to be passed to the function being called
Returns:
All the values returned by the called function. The first return value at index 0, the second at index 1 and so on.
Exceptions:
TypeMismatchError If this LuaVariable tries to subscript something that is not a table.
LuaRunTimeError If something bad happens while executing the function.

LuaValueList Diluculum::LuaVariable::operator() const LuaValue param1,
const LuaValue param2
 

Assuming that this LuaVariable holds a function, calls this function and returns its return values. Both "pure" Lua functions and functions written in C/C++ and "exported" to Lua are supported.

Parameters:
param1 The first parameter to be passed to the function being called
param2 The second parameter to be passed to the function being called
Returns:
All the values returned by the called function. The first return value at index 0, the second at index 1 and so on.
Exceptions:
TypeMismatchError If this LuaVariable tries to subscript something that is not a table.
LuaRunTimeError If something bad happens while executing the function.

LuaValueList Diluculum::LuaVariable::operator() const LuaValue param  ) 
 

Assuming that this LuaVariable holds a function, calls this function and returns its return values. Both "pure" Lua functions and functions written in C/C++ and "exported" to Lua are supported.

Parameters:
param The one and only parameter to be passed to the function being called
Returns:
All the values returned by the called function. The first return value at index 0, the second at index 1 and so on.
Exceptions:
TypeMismatchError If this LuaVariable tries to subscript something that is not a table.
LuaRunTimeError If something bad happens while executing the function.

LuaValueList Diluculum::LuaVariable::operator()  ) 
 

Assuming that this LuaVariable holds a function, calls this function (without passing any parameter to it) and returns its return values. Both "pure" Lua functions and functions written in C/C++ and "exported" to Lua are supported.

Returns:
All the values returned by the called function. The first return value at index 0, the second at index 1 and so on.
Exceptions:
TypeMismatchError If this LuaVariable tries to subscript something that is not a table.
LuaRunTimeError If something bad happens while executing the function.

LuaValueList Diluculum::LuaVariable::operator() const LuaValueList params  ) 
 

Assuming that this LuaVariable holds a function, calls this function and returns its return values. Both "pure" Lua functions and functions written in C/C++ and "exported" to Lua are supported.

Parameters:
params All the parameters to be passed to the function being called. The first parameter at index 0, the second at index 1 and so on.
Returns:
All the values returned by the called function. The first return value at index 0, the second at index 1 and so on.
Exceptions:
TypeMismatchError If this LuaVariable tries to subscript something that is not a table.
LuaRunTimeError If something bad happens while executing the function.

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

Assigns a new value to this LuaVariable. The corresponding variable in the Lua state is updated accordingly.

Note:
Notice that this is the assignment of a new value to a variable. The user is also allowed to assign a LuaVariable to another LuaVariable (using the compiler-generated assignment operator). In that case, the LuaVariable at the left hand side will refer to the same variable as the LuaVariable at the right hand side, but no values will be changed.
Parameters:
rhs The new value for the variable.
Returns:
rhs, so that a sequence of assignments, like a = b = c = 1; works. Actually, returning rhs is the same as returning this->value(), that perhaps make more sense.
Exceptions:
TypeMismatchError If this LuaVariable tries to subscript something that is not a table.
Note:
Part of this method's implementation is identical to the implementation of the DILUCULUM_REGISTER_OBJECT() macro. If someday the implementation here is replaced with something better, remember to change there, too.

bool Diluculum::LuaVariable::operator== const LuaVariable rhs  )  const [inline]
 

Checks whether this LuaVariable refers to the same variable as rhs.

Parameters:
rhs The variable against which the comparison will be done.
Returns:
true if both involved LuaVariables refer to the same variable. false otherwise.

Definition at line 234 of file LuaVariable.hpp.

References keys_, and state_.

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

Checks whether the value stored in this variable is equal to the value at rhs.

Parameters:
rhs The value against which the comparison will be done.
Returns:
true if this variable's value is equal to rhs. false otherwise.
Exceptions:
TypeMismatchError If this LuaVariable tries to subscript something that is not a table.

Definition at line 225 of file LuaVariable.hpp.

References value().

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

Assuming that this LuaVariable holds a table, returns the value whose index is key.

Parameters:
key The key whose value is desired.
Returns:
The value whose index is key.
Note:
This method doesn't throw anything, even if this LuaVariable doesn't hold a table. But an exception will be thrown if one tries to access the value of the returned variable (see value()).

void Diluculum::LuaVariable::pushLastTable  ) 
 

Pushes into the Lua stack the table storing this variable. Now, let's try to make this clearer... First, every Lua variable is stored in a table (even global variables, because Lua stores them in a "table of globals"). So, this method will find the table where this variable is stored (traversing a sequence of nested tables, if necessary), and push it onto the Lua stack (of the state_ Lua state).

Note:
This method exists mostly to allow a nicer implementation of other Diluculum features. Users aren't expected to call this.

void Diluculum::LuaVariable::pushTheReferencedValue  )  const [private]
 

Pushes onto the Lua stack the value referenced by this LuaVariable.

Exceptions:
TypeMismatchError If this LuaVariable tries to subscript something that is not a table.

LuaValue Diluculum::LuaVariable::value  )  const
 

Returns the value associated with this variable. If the variable does not exist, returns Nil.

Exceptions:
TypeMismatchError If this LuaVariable tries to subscript something that is not a table.

Referenced by operator==().


Friends And Related Function Documentation

friend class LuaState [friend]
 

Definition at line 45 of file LuaVariable.hpp.


Member Data Documentation

KeyList Diluculum::LuaVariable::keys_ [private]
 

The sequence of keys used to get to this variable. For a global variable, this will consist of a single key; for variables inside nested tables, this sequence can be arbitrarily long.

Just to relate this with the parameters passed to the constructor: this sequence equals to predKeys parameter, with the key parameter appended to it.

Definition at line 312 of file LuaVariable.hpp.

Referenced by getKeys(), operator!=(), and operator==().

lua_State* Diluculum::LuaVariable::state_ [private]
 

The Lua state in which this LuaVariable lives.

Definition at line 303 of file LuaVariable.hpp.

Referenced by getState(), operator!=(), and operator==().


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