Class QtLuaLocker provides means to directly access the Lua state lua_State* using the Lua API. This class ensures that the current thread has exclusive access to the Lua state.

QtLuaLocker::QtLuaLocker(QtLuaEngine *engine)

Create a QtLuaLocker object and ensures that the current thread has exclusive access to the Lua state for the Lua interpreter engine. This constructor hangs until obtaining the lock

QtLuaLocker::QtLuaLocker(QtLuaEngine *engine, int timeOut)

Create a QtLuaLocker object and ensures that the current thread has exclusive access to the Lua state for the Lua interpreter engine. This constructor hangs at most for timeOut milliseconds. To know whether the lock was acquired, cast the QtLuaLocker as a lua_State* pointer.

lua_State* QtLuaLocker::operator lua_State*()

Returns a lua_State* pointer to access the state of the Lua interpreter using the Lua API. Since this is a cast operator, one can simply pass the QtLuaLocker object whenever a lua_State* is expected. This cast returns 0 when the constructor was unable to acquire the exclusive lock during the specified timeout.

bool QtLuaLocker::isReady()

Returns true if the locking operation was successful and the interpreter is in ready state. Note that locking and state are distinct concepts. It is possible to lock a running interpreter while it is waiting for other events. The eval and evaluate functions use this test to decide whether to run a command.

void QtLuaLocker::setRunning()

Sets the interpreter to state Running. The engine will return to state Ready after the destruction of the last QtLuaLocker object and the execution of the queue. Temporary releasing the lock with unlock() keeps the engine in state Running. */

This can be useful if you plan to call the Lua API functions lua_call or lua_pcall and expect the code to run for an extended period of time.