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.

Members  

Functions  

Static function  

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.

Value at(const Value &key) const  

Index operation on global table.

See also State::operator[] function.

Value at(const String &key) const  

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

See also State::operator[] function.

void enable_qdebug_print(bool enabled = true)  

This function function may be used to enable forwarding of lua print function output to Qt debug output.

See also Predefined lua functions section.

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.

ValueBase::List exec_chunk(QIODevice &io)  

Execute a lua chuck read from QIODevice .

See also Error handling and exceptions section.

ValueBase::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.

lua_State * get_lua_state() const  

This function returns a pointer to the internal Lua state.

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.

int lua_version() const  

this function returns lua version. Result is 500 for lua pior to version 5.1.

bool openlib(Library lib)  

This function open a lua standard library or QtLua lua library. The function returns true if the library is available.

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"];

See also State::at function.

Value operator[](const String &key) const  

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

See also State::operator[] function and State::at 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 be assigned to modify original lua value:

// 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;

See also State::at function.

ValueRef operator[](const String &key)  

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

See also State::operator[] function and State::at function.

void output(const QString &str)  

This member is a Qt signal.

Text output signal. This signal is used to report errors and display output of the lua print() function.

See also Predefined lua functions section.

static template <typename QObject_T> void register_qobject_meta()  

This template function adds a new entry to the qt.meta lua table. This allows lua script to access QObject members and create new objects of this type using the qt.new_qobject lua function.

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 Sat Mar 30 15:29:54 2013 using MkDoc