State class reference
[Base module]

Declaration  

#include <QtLua/State>

namespace QtLua {
class State;
};

This class is a member of the QtLua namespace.

Description  

This class wraps the lua interpreter state.

This class provides various functions to execute lua code, access lua variables from C++ and load lua libraries.

Some functions in this class may throw an exception to handle lua errors, see Error handling and exceptions.

This class provides Qt slots and signals for use with the Console widget. This enables table names completion and error messages reporting on user console.

Inheritance  

Members  

Functions  

Slots  

  • void exec(const QString &statements)
  • void fill_completion_list(const QString &prefix, QStringList &list, int &cursor_offset)

Signal  

  • void output(const QString &str)

Members detail  

State()  

No documentation available

~State()  

Lua interpreter state is checked for remaining Value objects with references to UserData objects when destroyed.

Program is aborted if such references are found because these objects would try to access the destroyed State later and probably crash.

QtLua takes care of clearing all global variables before performing this sanity check.

void exec(const QString &statements)  

This member is a Qt slot.

This slot function execute the given script string and initiate a garbage collection cycle. It will catch and print lua errors using the State::output signal.

See also Console class.

Value::List exec_chunk(QIODevice &io)  

Execute a lua chuck read from QIODevice .

See also Error handling and exceptions section.

Value::List exec_statements(const String &statements)  

Execute a lua script string.

See also Error handling and exceptions section.

void fill_completion_list(const QString &prefix, QStringList &list, int &cursor_offset)  

This member is a Qt slot.

Lua global variables completion handler. May be connected to Console widget for default global variables completion behavior.

void gc_collect()  

Initiate a garbage collection cycle. This is useful to ensure all unused UserData based objects are destroyed.

Value get_global(const String &path) const  

Get global variable. If path contains '.', intermediate tables will be accessed. The State::operator[] function may be used if no intermediate table access is needed.

void lua_do(void (*func)(::lua_State *) )  

Call given function pointer with internal lua_State pointer. Can be used to register extra libraries or access internal lua interpreter directly.

Use with care if you are nor familiar with the lua C API.

void openlib(Library lib)  

This function open a lua standard library or QtLua lua library.

See also Library enum and QtLua lua libraries section.

Value operator[](const Value &key) const  

Index operation on global table. This function return a Value object which is a copy of the requested global variable. This value can be modified but will not change the original lua variable.

// code from examples/cpp/value/global.cc:32

QtLua::State state;
QtLua::State const & const_state = state;
// Access global table from lua
state.exec_statements("foo = 5");

// Access global table from C++
int foo = const_state["foo"];

Value operator[](const String &key) const  

Index operation on global table, shortcut for string key access

See also State::operator[] function.

ValueRef operator[](const Value &key)  

Index operation on global table. This function return a ValueRef object which is a modifiable reference to requested global variable. It can assigned to modify original lua variable:

// code from examples/cpp/value/global.cc:32

QtLua::State state;
// Access global table from lua
state.exec_statements("foo = 5");

// Access global table from C++
state["bar"] = 5;

ValueRef operator[](const String &key)  

Index operation on global table, shortcut for string key access.

See also State::operator[] function.

void output(const QString &str)  

This member is a Qt signal.

Text output signal. This signal is used to report errors and on lua print() function call (see Predefined lua functions).

void set_global(const String &path, const Value &value)  

Set a global variable. If path contains '.', intermediate tables will be created on the fly. The State::operator[] function may be used if no intermediate table access is needed.

Valid XHTML 1.0 StrictGenerated by diaxen on Mon Aug 15 03:23:06 2011 using MkDoc