diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-03-19 19:39:07 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-03-19 19:39:07 -0300 |
commit | e3c0ce9a6977c750eca72dcf173bcffaf01a11d7 (patch) | |
tree | d58ddaf36392ea747654b078c450fdfb1f8e9a15 /manual.tex | |
parent | 85b76bcc01141a118a22203798b7206d943ac072 (diff) | |
download | lua-e3c0ce9a6977c750eca72dcf173bcffaf01a11d7.tar.gz lua-e3c0ce9a6977c750eca72dcf173bcffaf01a11d7.tar.bz2 lua-e3c0ce9a6977c750eca72dcf173bcffaf01a11d7.zip |
dofile accepts pre-compiled chunks.
lua_is... do coercion.
small correction: = versus ==.
Diffstat (limited to 'manual.tex')
-rw-r--r-- | manual.tex | 33 |
1 files changed, 23 insertions, 10 deletions
@@ -1,4 +1,4 @@ | |||
1 | % $Id: manual.tex,v 1.11 1996/02/16 13:12:12 roberto Exp roberto $ | 1 | % $Id: manual.tex,v 1.12 1996/03/14 17:45:01 roberto Exp roberto $ |
2 | 2 | ||
3 | \documentstyle[A4,11pt,bnf]{article} | 3 | \documentstyle[A4,11pt,bnf]{article} |
4 | 4 | ||
@@ -13,7 +13,7 @@ | |||
13 | \newcommand{\Def}[1]{{\em #1}\index{#1}} | 13 | \newcommand{\Def}[1]{{\em #1}\index{#1}} |
14 | \newcommand{\Deffunc}[1]{\index{#1}} | 14 | \newcommand{\Deffunc}[1]{\index{#1}} |
15 | 15 | ||
16 | \newcommand{\Version}{2.3} | 16 | \newcommand{\Version}{2.4} |
17 | 17 | ||
18 | \makeindex | 18 | \makeindex |
19 | 19 | ||
@@ -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/02/16 13:12:12 $} | 37 | \date{\small \verb$Date: 1996/03/14 17:45:01 $} |
38 | 38 | ||
39 | \maketitle | 39 | \maketitle |
40 | 40 | ||
@@ -137,7 +137,11 @@ of new functions% | |||
137 | \footnote{Actually, a function definition is an | 137 | \footnote{Actually, a function definition is an |
138 | assignment to a global variable; \see{TypesSec}.}. | 138 | assignment to a global variable; \see{TypesSec}.}. |
139 | 139 | ||
140 | 140 | Chunks may be pre-compiled; see program \IndexVerb{luac} for details. | |
141 | Ascii files with chunk code and their binary pre-compiled forms | ||
142 | are interchangeable. | ||
143 | Lua automatically detects the file type and acts accordingly. | ||
144 | \index{pre-compilation} | ||
141 | 145 | ||
142 | \section{\Index{Types}} \label{TypesSec} | 146 | \section{\Index{Types}} \label{TypesSec} |
143 | 147 | ||
@@ -412,7 +416,7 @@ Otherwise, their values are compared. | |||
412 | Numbers and strings are compared in the usual way. | 416 | Numbers and strings are compared in the usual way. |
413 | Tables, CFunctions, and functions are compared by reference, | 417 | Tables, CFunctions, and functions are compared by reference, |
414 | that is, two tables are considered equal only if they are the same table. | 418 | that is, two tables are considered equal only if they are the same table. |
415 | The operator \verb'~=' is exactly the negation of equality (\verb'='). | 419 | The operator \verb'~=' is exactly the negation of equality (\verb'=='). |
416 | 420 | ||
417 | The other operators work as follows. | 421 | The other operators work as follows. |
418 | If both arguments are numbers, they are compared as such. | 422 | If both arguments are numbers, they are compared as such. |
@@ -444,7 +448,7 @@ Otherwise, the fallback ``concat'' is called; \see{fallback}. | |||
444 | from the lower to the higher priority: | 448 | from the lower to the higher priority: |
445 | \begin{verbatim} | 449 | \begin{verbatim} |
446 | and or | 450 | and or |
447 | < > <= >= ~= = | 451 | < > <= >= ~= == |
448 | .. | 452 | .. |
449 | + - | 453 | + - |
450 | * / | 454 | * / |
@@ -740,7 +744,7 @@ The API functions can be classified in the following categories: | |||
740 | All API functions are declared in the file \verb'lua.h'. | 744 | All API functions are declared in the file \verb'lua.h'. |
741 | 745 | ||
742 | \subsection{Executing Lua Code} | 746 | \subsection{Executing Lua Code} |
743 | A host program can execute Lua programs written in a file or in a string, | 747 | A host program can execute Lua chunks written in a file or in a string, |
744 | using the following functions: | 748 | using the following functions: |
745 | \Deffunc{lua_dofile}\Deffunc{lua_dostring} | 749 | \Deffunc{lua_dofile}\Deffunc{lua_dostring} |
746 | \begin{verbatim} | 750 | \begin{verbatim} |
@@ -751,6 +755,9 @@ Both functions return an error code: | |||
751 | 0, in case of success; non zero, in case of errors. | 755 | 0, in case of success; non zero, in case of errors. |
752 | The function \verb'lua_dofile', if called with argument NULL (0), | 756 | The function \verb'lua_dofile', if called with argument NULL (0), |
753 | executes the ``file'' {\tt stdin}. | 757 | executes the ``file'' {\tt stdin}. |
758 | Function \verb'lua_dofile' is also able to execute pre-compiled chunks. | ||
759 | It detects whether the file is text or not, | ||
760 | and loads it accordingly (see program \IndexVerb{luac}). | ||
754 | 761 | ||
755 | \subsection{Converting Values between C and Lua} \label{valuesCLua} | 762 | \subsection{Converting Values between C and Lua} \label{valuesCLua} |
756 | Because Lua has no static type system, | 763 | Because Lua has no static type system, |
@@ -788,19 +795,24 @@ the following function is available: | |||
788 | \begin{verbatim} | 795 | \begin{verbatim} |
789 | int lua_type (lua_Object object); | 796 | int lua_type (lua_Object object); |
790 | \end{verbatim} | 797 | \end{verbatim} |
791 | plus the following macros: | 798 | plus the following macros and functions: |
792 | \Deffunc{lua_isnil}\Deffunc{lua_isnumber}\Deffunc{lua_isstring} | 799 | \Deffunc{lua_isnil}\Deffunc{lua_isnumber}\Deffunc{lua_isstring} |
793 | \Deffunc{lua_istable}\Deffunc{lua_iscfunction}\Deffunc{lua_isuserdata} | 800 | \Deffunc{lua_istable}\Deffunc{lua_iscfunction}\Deffunc{lua_isuserdata} |
801 | \Deffunc{lua_isfunction} | ||
794 | \begin{verbatim} | 802 | \begin{verbatim} |
795 | int lua_isnil (lua_Object object); | 803 | int lua_isnil (lua_Object object); |
796 | int lua_isnumber (lua_Object object); | 804 | int lua_isnumber (lua_Object object); |
797 | int lua_isstring (lua_Object object); | 805 | int lua_isstring (lua_Object object); |
798 | int lua_istable (lua_Object object); | 806 | int lua_istable (lua_Object object); |
807 | int lua_isfunction (lua_Object object); | ||
799 | int lua_iscfunction (lua_Object object); | 808 | int lua_iscfunction (lua_Object object); |
800 | int lua_isuserdata (lua_Object object); | 809 | int lua_isuserdata (lua_Object object); |
801 | \end{verbatim} | 810 | \end{verbatim} |
802 | All macros return 1 if the object has the given type, | 811 | All macros return 1 if the object is compatible with the given type, |
803 | and 0 otherwise. | 812 | and 0 otherwise. |
813 | \verb'lua_isnumber' accepts numbers and numerical strings, | ||
814 | \verb'lua_isstring' accepts strings and numbers (\see{coercion}), | ||
815 | and \verb'lua_isfunction' accepts Lua and C functions. | ||
804 | 816 | ||
805 | The function \verb'lua_type' can be used to distinguish between | 817 | The function \verb'lua_type' can be used to distinguish between |
806 | different kinds of user data; see below. | 818 | different kinds of user data; see below. |
@@ -1113,7 +1125,8 @@ declared in \verb-lualib.h-. | |||
1113 | 1125 | ||
1114 | \subsubsection*{{\tt dofile (filename)}}\Deffunc{dofile} | 1126 | \subsubsection*{{\tt dofile (filename)}}\Deffunc{dofile} |
1115 | This function receives a file name, | 1127 | This function receives a file name, |
1116 | opens it and executes its contents as a Lua chunk. | 1128 | opens it and executes its contents as a Lua chunk, |
1129 | or as pre-compiled chunks. | ||
1117 | When called without arguments, | 1130 | When called without arguments, |
1118 | it executes the contents of the standard input. | 1131 | it executes the contents of the standard input. |
1119 | It returns 1 if there are no errors, \nil\ otherwise. | 1132 | It returns 1 if there are no errors, \nil\ otherwise. |