312 lines
5.8 KiB
HTML
312 lines
5.8 KiB
HTML
<HTML
|
|
><HEAD
|
|
><TITLE
|
|
>The Pike tag</TITLE
|
|
><META
|
|
NAME="GENERATOR"
|
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
|
"><LINK
|
|
REL="HOME"
|
|
TITLE="Caudium HOWTO"
|
|
HREF="index.html"><LINK
|
|
REL="UP"
|
|
TITLE="Developing with Caudium"
|
|
HREF="developing.html"><LINK
|
|
REL="PREVIOUS"
|
|
TITLE="Your first RXML file"
|
|
HREF="firstrxml.html"><LINK
|
|
REL="NEXT"
|
|
TITLE="Your first Pike script"
|
|
HREF="firstpikescript.html"></HEAD
|
|
><BODY
|
|
CLASS="sect1"
|
|
BGCOLOR="#FFFFFF"
|
|
TEXT="#000000"
|
|
LINK="#0000FF"
|
|
VLINK="#840084"
|
|
ALINK="#0000FF"
|
|
><DIV
|
|
CLASS="NAVHEADER"
|
|
><TABLE
|
|
SUMMARY="Header navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TH
|
|
COLSPAN="3"
|
|
ALIGN="center"
|
|
>Caudium HOWTO</TH
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="left"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="firstrxml.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="80%"
|
|
ALIGN="center"
|
|
VALIGN="bottom"
|
|
>Chapter 6. Developing with Caudium</TD
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="right"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="firstpikescript.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"></DIV
|
|
><DIV
|
|
CLASS="sect1"
|
|
><H1
|
|
CLASS="sect1"
|
|
><A
|
|
NAME="thePiketag">6.2. The Pike tag</H1
|
|
><P
|
|
> For a complete tutorial and reference manual on Pike, see
|
|
<A
|
|
HREF="http://pike.oav.net/"
|
|
TARGET="_top"
|
|
>http://pike.oav.net/</A
|
|
>.
|
|
</P
|
|
><P
|
|
> The Pike tag allows you to easily insert Pike code into your HTML page à la
|
|
PHP. This is a good way of learning Pike if you have a PHP background or if
|
|
you want to do things very easily and don't worry about perfect results.
|
|
</P
|
|
><P
|
|
> To do this, you have to load a module in your server. Just select <TT
|
|
CLASS="option"
|
|
>Load
|
|
module</TT
|
|
> in the <SPAN
|
|
CLASS="abbrev"
|
|
>CIF.</SPAN
|
|
> and click the <SPAN
|
|
CLASS="QUOTE"
|
|
>"Pike tag"</SPAN
|
|
> image. Then hit save and create
|
|
an .html file where your public web files are. Since everybody tells me
|
|
that PHP is easy, which is why it's so popular, I took the PHP examples and
|
|
converted them to Pike. Here is the result:
|
|
</P
|
|
><DIV
|
|
CLASS="example"
|
|
><A
|
|
NAME="AEN896"><P
|
|
><B
|
|
>Example 6-2. The PHP documentation as a Pike tag.</B
|
|
></P
|
|
><TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><FONT
|
|
COLOR="#000000"
|
|
><PRE
|
|
CLASS="programlisting"
|
|
> <html>
|
|
<body bgcolor="#FFFFFF">
|
|
<h2>Escaping from HTML</h2>
|
|
<p>
|
|
There is one way of escaping from HTML and entering "Pike code mode"
|
|
<br />
|
|
<Pike>
|
|
output("This is the simplest, and SGML processing instruction");
|
|
</Pike>
|
|
</p>
|
|
<h2>Instruction separation</h2>
|
|
<p>
|
|
Instructions are separated the same as in C or Perl:
|
|
terminate each statement with a semicolon.
|
|
The closing tag (container, in fact) also implies the end of the statement,
|
|
so the following are equivalent:
|
|
<br />
|
|
<Pike>
|
|
output ("This is a test");
|
|
</Pike>
|
|
<br />
|
|
<Pike> output ("This is a test"); </Pike>
|
|
</p>
|
|
<h2>Comments</h2>
|
|
<p>
|
|
Pike supports C, C++ but not Unix shell-style comments. For example:
|
|
<Pike>
|
|
string tests = "This is a test<br />"; // this is a one-line C++ style comment
|
|
/* This is a multi line comment
|
|
yet another line of comment */
|
|
tests += "Yet another test";
|
|
return tests;
|
|
</Pike>
|
|
</p>
|
|
<h2>Melding RXML and Pike</h2>
|
|
You will never see this in PHP.
|
|
<A
|
|
NAME="AEN899"
|
|
HREF="#FTN.AEN899"
|
|
>[1]</A
|
|
>
|
|
This will create a .gif image of 1-2-...-255.
|
|
This took 0.4s on my Duron 750 the first time and 0.1s after.
|
|
<p>
|
|
<gtext scale=0.5>
|
|
<Pike>
|
|
string output = "";
|
|
for(int I = 1; I < 255; I++)
|
|
output += I + "-";
|
|
return output;
|
|
</Pike>
|
|
</gtext>
|
|
</p>
|
|
</body>
|
|
</html>
|
|
</PRE
|
|
></FONT
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
></DIV
|
|
><P
|
|
> The problem with using this is that you will soon see it is not powerful:
|
|
</P
|
|
><P
|
|
></P
|
|
><UL
|
|
><LI
|
|
><P
|
|
> The code will become an ugly mixture of data and code even if you use an object
|
|
orientation method. The more your project grows, the less you will be able
|
|
to produce something useful.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> The URL will require plenty of those <SPAN
|
|
CLASS="QUOTE"
|
|
>"&"</SPAN
|
|
> symbols and you will have a lot of files
|
|
without real organization.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> The performance will not be the best.
|
|
</P
|
|
></LI
|
|
><LI
|
|
><P
|
|
> This can be considered as a security risk for servers that are opened
|
|
to unknown users (eg. public web servers).
|
|
</P
|
|
></LI
|
|
></UL
|
|
><P
|
|
> The next step is to write your first Pike script.
|
|
</P
|
|
></DIV
|
|
><H3
|
|
CLASS="FOOTNOTES"
|
|
>Notes</H3
|
|
><TABLE
|
|
BORDER="0"
|
|
CLASS="FOOTNOTES"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
ALIGN="LEFT"
|
|
VALIGN="TOP"
|
|
WIDTH="5%"
|
|
><A
|
|
NAME="FTN.AEN899"
|
|
HREF="thepiketag.html#AEN899"
|
|
>[1]</A
|
|
></TD
|
|
><TD
|
|
ALIGN="LEFT"
|
|
VALIGN="TOP"
|
|
WIDTH="95%"
|
|
><P
|
|
>In fact you can... just compile PHP for Caudium :)</P
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><DIV
|
|
CLASS="NAVFOOTER"
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"><TABLE
|
|
SUMMARY="Footer navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="firstrxml.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="index.html"
|
|
ACCESSKEY="H"
|
|
>Home</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="firstpikescript.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
>Your first RXML file</TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="developing.html"
|
|
ACCESSKEY="U"
|
|
>Up</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
>Your first Pike script</TD
|
|
></TR
|
|
></TABLE
|
|
></DIV
|
|
></BODY
|
|
></HTML
|
|
> |