Next: 6 Predefined Functions and Up: 5 The Application Program Previous: 5.5 C Functions

5.6 Locking Lua Objects

As already noted, lua_Objects are volatile. If the C code needs to keep a lua_Object outside block boundaries, it has to lock the object. The routines to manipulate locking are the following:

int        lua_lock (void);
lua_Object lua_getlocked  (int ref);
void       lua_pushlocked (int ref);
void       lua_unlock (int ref);
The function lua_lock locks the object which is on the top of the stack, and returns a reference to it. Whenever the locked object is needed, a call to lua_getlocked returns a handle to it, while lua_pushlocked pushes the handle on the stack. When a locked object is no longer needed, it can be unlocked with a call to lua_unlock.


Next: 6 Predefined Functions and Up: 5 The Application Program Previous: 5.5 C Functions