aboutsummaryrefslogtreecommitdiff
path: root/manual.tex
diff options
context:
space:
mode:
Diffstat (limited to 'manual.tex')
-rw-r--r--manual.tex75
1 files changed, 46 insertions, 29 deletions
diff --git a/manual.tex b/manual.tex
index 5a179cd0..539385a6 100644
--- a/manual.tex
+++ b/manual.tex
@@ -1,4 +1,4 @@
1% $Id: manual.tex,v 1.14 1996/03/20 18:44:02 roberto Exp roberto $ 1% $Id: manual.tex,v 1.15 1996/04/01 14:36:35 roberto Exp roberto $
2 2
3\documentstyle[fullpage,11pt,bnf]{article} 3\documentstyle[fullpage,11pt,bnf]{article}
4 4
@@ -34,7 +34,7 @@ Waldemar Celes Filho
34\tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio 34\tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio
35} 35}
36 36
37\date{\small \verb$Date: 1996/03/20 18:44:02 $} 37\date{\small \verb$Date: 1996/04/01 14:36:35 $}
38 38
39\maketitle 39\maketitle
40 40
@@ -739,7 +739,7 @@ The API functions can be classified in the following categories:
739\item manipulating (reading and writing) Lua objects; 739\item manipulating (reading and writing) Lua objects;
740\item calling Lua functions; 740\item calling Lua functions;
741\item C functions to be called by Lua; 741\item C functions to be called by Lua;
742\item locking Lua Objects. 742\item references to Lua Objects.
743\end{enumerate} 743\end{enumerate}
744All API functions are declared in the file \verb'lua.h'. 744All API functions are declared in the file \verb'lua.h'.
745 745
@@ -1069,30 +1069,39 @@ many results.
1069Section~\ref{exCFunction} presents an example of a CFunction. 1069Section~\ref{exCFunction} presents an example of a CFunction.
1070 1070
1071 1071
1072\subsection{Locking Lua Objects} 1072\subsection{References to Lua Objects}
1073 1073
1074As already noted, \verb'lua_Object's are volatile. 1074As already noted, \verb'lua_Object's are volatile.
1075If the C code needs to keep a \verb'lua_Object' 1075If the C code needs to keep a \verb'lua_Object'
1076outside block boundaries, 1076outside block boundaries,
1077it has to {\em lock} the object. 1077it must create a \Def{reference} to the object.
1078The routines to manipulate locking are the following: 1078The routines to manipulate references are the following:
1079\Deffunc{lua_lock}\Deffunc{lua_getlocked} 1079\Deffunc{lua_ref}\Deffunc{lua_getref}
1080\Deffunc{lua_pushlocked}\Deffunc{lua_unlock} 1080\Deffunc{lua_pushref}\Deffunc{lua_unref}
1081\begin{verbatim} 1081\begin{verbatim}
1082int lua_lock (void); 1082typedef int lua_Reference;
1083lua_Object lua_getlocked (int ref); 1083
1084void lua_pushlocked (int ref); 1084lua_Reference lua_ref (int lock);
1085void lua_unlock (int ref); 1085lua_Object lua_getref (lua_Reference ref);
1086\end{verbatim} 1086void lua_pushref (lua_Reference ref);
1087The function \verb'lua_lock' locks the object 1087void lua_unref (lua_Reference ref);
1088which is on the top of the stack, 1088\end{verbatim}
1089and returns a reference to it. 1089The function \verb'lua_ref' creates a reference
1090Whenever the locked object is needed, 1090to the object which is on the top of the stack,
1091a call to \verb'lua_getlocked' 1091and returns this reference.
1092If \verb'lock' is true, the object is {\em locked}:
1093that means the object will not be garbage collected.
1094Notice that an unlocked reference may be garbage collected.
1095Whenever the referenced object is needed,
1096a call to \verb'lua_getref'
1092returns a handle to it, 1097returns a handle to it,
1093while \verb'lua_pushlocked' pushes the handle on the stack. 1098while \verb'lua_pushref' pushes the object on the stack.
1094When a locked object is no longer needed, 1099If the object has been collected,
1095it can be unlocked with a call to \verb'lua_unlock'. 1100\verb'lua_getref' returns \verb'LUA_NOOBJECT',
1101and \verb'lua_pushobject' issues an error.
1102
1103When a reference is no longer needed,
1104it can be freed with a call to \verb'lua_unref'.
1096 1105
1097 1106
1098 1107
@@ -1839,12 +1848,14 @@ as illustrated in Figure~\ref{Cinher}.
1839\begin{figure} 1848\begin{figure}
1840\Line 1849\Line
1841\begin{verbatim} 1850\begin{verbatim}
1842int lockedParentName; /* stores the lock index for the string "parent" */ 1851#include "lua.h"
1843int lockedOldIndex; /* previous fallback function */ 1852
1853lua_Reference lockedParentName; /* lock index for the string "parent" */
1854lua_Reference lockedOldIndex; /* previous fallback function */
1844 1855
1845void callOldFallback (lua_Object table, lua_Object index) 1856void callOldFallback (lua_Object table, lua_Object index)
1846{ 1857{
1847 lua_Object oldIndex = lua_getlocked(lockedOldIndex); 1858 lua_Object oldIndex = lua_getref(lockedOldIndex);
1848 lua_pushobject(table); 1859 lua_pushobject(table);
1849 lua_pushobject(index); 1860 lua_pushobject(index);
1850 lua_callfunction(oldIndex); 1861 lua_callfunction(oldIndex);
@@ -1861,7 +1872,7 @@ void Index (void)
1861 return; 1872 return;
1862 } 1873 }
1863 lua_pushobject(table); 1874 lua_pushobject(table);
1864 lua_pushlocked(lockedParentName); 1875 lua_pushref(lockedParentName);
1865 parent = lua_getsubscript(); 1876 parent = lua_getsubscript();
1866 if (lua_istable(parent)) 1877 if (lua_istable(parent))
1867 { 1878 {
@@ -1880,9 +1891,9 @@ void Index (void)
1880This code must be registered with: 1891This code must be registered with:
1881\begin{verbatim} 1892\begin{verbatim}
1882 lua_pushstring("parent"); 1893 lua_pushstring("parent");
1883 lockedParentName = lua_lock(); 1894 lockedParentName = lua_ref(1);
1884 lua_pushobject(lua_setfallback("index", Index)); 1895 lua_pushobject(lua_setfallback("index", Index));
1885 lockedOldIndex = lua_lock(); 1896 lockedOldIndex = lua_ref(1);
1886\end{verbatim} 1897\end{verbatim}
1887Notice how the string \verb'"parent"' is kept 1898Notice how the string \verb'"parent"' is kept
1888locked in Lua for optimal performance. 1899locked in Lua for optimal performance.
@@ -1892,6 +1903,9 @@ There are many different ways to do object-oriented programming in Lua.
1892This section presents one possible way to 1903This section presents one possible way to
1893implement classes, 1904implement classes,
1894using the inheritance mechanism presented above. 1905using the inheritance mechanism presented above.
1906{\em Please notice: the following examples only work
1907with the index fallback redefined according to
1908Section~\ref{exfallback}}.
1895 1909
1896As one could expect, a good way to represent a class is 1910As one could expect, a good way to represent a class is
1897as a table. 1911as a table.
@@ -2079,9 +2093,12 @@ have been superseded by the new version of function \verb'date'.
2079Function \verb'int2str' (from \verb'strlib') has been superseded by new 2093Function \verb'int2str' (from \verb'strlib') has been superseded by new
2080function \verb'format', with parameter \verb'"%c"'. 2094function \verb'format', with parameter \verb'"%c"'.
2081\item 2095\item
2096The lock mechanism has been superseded by the reference mechanism.
2097However, \verb-lua.h- provides compatibility macros,
2098so there is no need to change programs.
2099\item
2082API function \verb'lua_pushliteral' now is just a macro to 2100API function \verb'lua_pushliteral' now is just a macro to
2083\verb'lua_pushstring'. 2101\verb'lua_pushstring'.
2084Programmers are encouraged not to use this macro.
2085\end{itemize} 2102\end{itemize}
2086 2103
2087\subsection*{Incompatibilities with \Index{version 2.1}} 2104\subsection*{Incompatibilities with \Index{version 2.1}}