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
- State()
- ~State()
- Value at(const Value &key) const
- Value at(const String &key) const
- void enable_qdebug_print(bool enabled = [...])
- ValueBase::List exec_chunk(QIODevice &io)
- ValueBase::List exec_statements(const String &statements)
- void gc_collect()
- Value get_global(const String &path) const
- lua_State * get_lua_state() const
- void lua_do(void (*func)(::lua_State *) )
- int lua_version() const
- bool openlib(Library lib)
- Value operator[](const Value &key) const
- Value operator[](const String &key) const
- ValueRef operator[](const Value &key)
- ValueRef operator[](const String &key)
- void set_global(const String &path, const Value &value)
Static function
- static template void register_qobject_meta()
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
No documentation available
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.
Index operation on global table.
See also State::operator[] function.
Index operation on global table, shortcut for string key access.
See also State::operator[] function.
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.
Execute a lua chuck read from QIODevice .
See also Error handling and exceptions section.
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.
Initiate a garbage collection cycle. This is useful to ensure all unused UserData based objects are destroyed.
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.
This function returns a pointer to the internal 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.
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.
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.
Index operation on global table, shortcut for string key access.
See also State::operator[] function and State::at function.
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.
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.
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.
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.