⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch08_69.htm

📁 by Randal L. Schwartz and Tom Phoenix ISBN 0-596-00132-0 Third Edition, published July 2001. (See
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<html><head><title>ExtUtils::Constant (Perl in a Nutshell, 2nd Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Stephen Spainhour" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly &amp; Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="0596002416L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Perl in a Nutshell, 2nd Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Java and XSLT" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch08_68.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228" /><td align="right" valign="top" width="228"><a href="ch08_70.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><h2 class="sect1">8.69. ExtUtils::Constant</h2><p><a name="INDEX-1402" />Generates XS code to import C headerconstants, allowing Perl modules to AUTOLOAD constants defined in Clibrary header files. Generally, you should not touchExtUtils::Constant functions, since they are already implemented by<i class="command">h2xs</i>.</p><p>For example:</p><blockquote><pre class="code">use ExtUtils::Constant qw (WriteConstants);WriteConstants(    NAME =&gt; `Nate',    NAMES =&gt; [qw(Nate Nathan Nathaniel)], # not Nat);# Generates wrapper code to make the values of the constants# Nate Nathan Nathaniel available to perl</pre></blockquote><p>Currently, this module understands the following types, although<i class="command">h2xs</i> may only know a subset. The sizes of thenumeric types are chosen by the <i class="command">Configure</i> scriptat compile time.</p><dl><dt><b><tt class="literal">IV</tt>  </b></dt><dd>Signed integer. At least 32 bits.</p></dd><dt><b><tt class="literal">UV</tt> </b></dt><dd>Unsigned integer. The same size as <tt class="literal">IV</tt>.</p></dd><dt><b><tt class="literal">NV</tt>  </b></dt><dd>Floating-point type. Probably <tt class="literal">double</tt>. Possibly<tt class="literal">long double</tt>.</p></dd><dt><b><tt class="literal">PV NUL[L]</tt> </b></dt><dd>Terminated string. Length will be determined with<tt class="literal">strlen</tt>.</p></dd><dt><b><tt class="literal">PVN</tt> </b></dt><dd>A fixed-length thing, given as a pointer, length pair. If you knowthe length of a string at compile time, you can use this instead of<tt class="literal">PV</tt>.</p></dd><dt><b><tt class="literal">SV</tt>  </b></dt><dd>A mortal SV.</p></dd><dt><b><tt class="literal">YES</tt> </b></dt><dd>Truth (<tt class="literal">PL_sv_yes</tt>). The value is not needed (and isignored).</p></dd><dt><b><tt class="literal">NO</tt>  </b></dt><dd>Defined falsehood (<tt class="literal">PL_sv_no</tt>). The value is notneeded (and is ignored).</p></dd><dt><b><tt class="literal">UNDEF</tt> </b></dt><dd>The value of the macro is not needed.</p></dd></dl><p>ExtUtils::Constant implements the following functions.</p><a name="INDEX-1403" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>assign</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>assign <em class="replaceable">indent</em>, <em class="replaceable">type</em>, <em class="replaceable">pre</em>, <em class="replaceable">post</em>, <em class="replaceable">value</em> ...</pre><p><tt class="literal">R</tt>eturns a suitable assignment clause. If<em class="replaceable"><tt>type</tt></em> is aggregate (e.g.,<tt class="literal">PVN</tt> expects both pointer and length), then thereshould be multiple <em class="replaceable"><tt>value</tt></em>s for thecomponents. <em class="replaceable"><tt>pre</tt></em> and<em class="replaceable"><tt>post</tt></em>, if defined, give snippets of C codeto proceed and follow the assignment. <em class="replaceable"><tt>pre</tt></em>is at the start of a block, so variables may be defined in it.</p></div><a name="INDEX-1404" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>autoload</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>autoload <em class="replaceable">package</em>, <em class="replaceable">version</em>, <em class="replaceable">autoloader</em></pre><p>Generates the <tt class="literal">AUTOLOAD</tt> subroutine for the module<em class="replaceable"><tt>package</tt></em>.<em class="replaceable"><tt>version</tt></em> is the Perl version with which thecode should be backwards-compatible. It defaults to the version ofPerl running the subroutine. If <em class="replaceable"><tt>autoloader</tt></em>is true, the <tt class="literal">AUTOLOAD</tt> subroutine falls back on<tt class="literal">AutoLoader::AUTOLOAD</tt> for all names that the<tt class="literal">constant()</tt> routine doesn'trecognize.</p></div><a name="INDEX-1405" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>C_constant</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>C_constant <em class="replaceable">package</em>, <em class="replaceable">subname</em>, <em class="replaceable">default_type</em>, <em class="replaceable">types</em>, <em class="replaceable">indent</em>,  <em class="replaceable">breakout, item ...</em></pre><p>Returns a list of C subroutine definitions that return the value andtype of constants when passed the name by the XS wrapper.<em class="replaceable"><tt>item...</tt></em> gives a list of constant names.These can be strings, which are taken as a C macro name, orreferences to a hash with the following keys:</p><dl><dt><b><tt class="literal">name</tt>    </b></dt><dd>The name of the constant, as seen by the Perl code.</p></dd><dt><b><tt class="literal">type</tt>    </b></dt><dd>The type of the constant (<tt class="literal">IV</tt>,<tt class="literal">NV</tt>, etc.).</p></dd><dt><b><tt class="literal">value</tt>   </b></dt><dd>A C expression for the value of the constant, or a list of Cexpressions if the type is aggregate. Defaults to<tt class="literal">name</tt> if not given.</p></dd><dt><b><tt class="literal">macro</tt>   </b></dt><dd>The C preprocessor macro to use in the <tt class="literal">#ifdef</tt>.Defaults to <tt class="literal">name</tt> and is primarily used if<tt class="literal">value</tt> is an <tt class="literal">enum</tt>. If areference or an array is passed, then the first element is used inplace of the <tt class="literal">#ifdef</tt> line, and the second elementis used in place of the <tt class="literal">#endif</tt>. This allowspreprocessor constructions such as:</p><blockquote><pre class="code">#if defined (foo)#if !defined (bar)...#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -