1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
<HTML><HEAD>
<TITLE>C Examples -- Example 5: tclhello</TITLE>
<LINK rel=Previous href="c-app4.htm">
<LINK rel=ToC href="toc.htm">
<LINK rel=Index href="master.htm">
<LINK rel=Next href="c-app6.htm">
</HEAD><BODY BGCOLOR="#ffffff"><A NAME="topofpage"></A>
<TABLE WIDTH=100%>
<TR>
<TD ALIGN=LEFT>
<A NAME="topofpage"></A> <IMG SRC="as-c-sm.gif">
</TD>
<TD ALIGN=RIGHT>
<A href="c-app4.htm"><IMG BORDER="0" src=navbprev.gif alt="[ Previous ]"></A>
<A href=toc.htm> <IMG BORDER="0" src=navbhome.gif alt="[ Contents ]"></A>
<A href=master.htm> <IMG BORDER="0" src=navbhelp.gif alt="[ Index ]"></A>
<A href="c-app6.htm"> <IMG BORDER="0" src=navbnext.gif alt="[ Next ]"></A>
<A name="7983"> </A>
</TD>
</TR>
</TABLE>
<a name="16799">
</a><h3>Example 5: tclhello</h3>
<p><a name="16800">
</a>The following example illustrates how to extend the Tcl scripting language built into the AOLserver with your own custom C code.</p>
<p><a name="16812">
</a>This example can be found in the <code>examples/c/tclhello</code> directory.</p>
<pre> <a name="16797"></a>
<a name="16826"></a>#include "nstcl.h"
<a name="16831"></a>
<a name="16832"></a>/*
<a name="16833"></a> * This code adds a new TCL command named "hello" to the AOLserver.
<a name="16834"></a> * To test this module, add the following to the
<a name="16835"></a> * [ns\server\server-name\modules] section of your nsd.ini file:
<a name="16836"></a> * tclhello=tclhello.dll ; or tclhello.so on Unix platforms
<a name="16837"></a> *
<a name="16838"></a> * You can then run your "hello" command from the /NS/EvalTcl
<a name="16839"></a> * interface provided by the AOLserver.
<a name="16840"></a> */
<a name="16841"></a>
<a name="16842"></a>int Ns_ModuleVersion = 1;
<a name="16843"></a>static Tcl_CmdProc HelloCmd;
<a name="16844"></a>
<a name="16845"></a>static int
<a name="16846"></a>HelloCmd(ClientData dummy, Tcl_Interp *interp, int argc, char **argv)
<a name="16847"></a>{
<a name="16848"></a> interp->result = "Hello";
<a name="16849"></a> return TCL_OK;
<a name="16850"></a>}
<a name="16851"></a>
<a name="16852"></a>static int
<a name="16853"></a>HelloInterpInit(Tcl_Interp *interp, void *context)
<a name="16854"></a>{
<a name="16855"></a> Tcl_CreateCommand(interp, "hello", HelloCmd, NULL, NULL);
<a name="16856"></a> return NS_OK;
<a name="16857"></a>}
<a name="16858"></a>
<a name="16859"></a>int
<a name="16860"></a>Ns_ModuleInit(char *hServer, char *hModule)
<a name="16861"></a>{
<a name="16862"></a> return (Ns_TclInitInterps(hServer, HelloInterpInit, NULL));
<a name="16863"></a>}
<a name="16864"></a>
<a name="16865"></a>
</pre><p>
<TABLE BORDER="2" CELLPADDING="1" width="100%">
<TR><TD COLSPAN=3><P ALIGN=Center>
<IMG SRC="bluebult.gif">
<A HREF="#topofpage">
<FONT SIZE=-1>Top of Page</FONT></A>
<IMG SRC="bluebult.gif">
</TD></TR>
<TR><TD COLSPAN=3><P ALIGN=Center>
<A href="c-app4.htm">
<IMG BORDER="0" src=navbprev.gif alt="[ Previous ]"></A>
<A href=toc.htm>
<IMG BORDER="0" src=navbhome.gif alt="[ Contents ]"></A>
<A href=master.htm>
<IMG BORDER="0" src=navbhelp.gif alt="[ Index ]"></A>
<A href="c-app6.htm">
<IMG BORDER="0" src=navbnext.gif alt="[ Next ]"></A>
<BR align=center>
<FONT size=-1>Copyright © 1998-99 America Online,
Inc.</FONT>
</TD></TR></TABLE></BODY></HTML>
|