[Crossfire-wiki] [Crossfire Wiki] page changed: client_side_scripting:client_scripting_interface-basic_howto

no-reply_wiki at cross-fire.org no-reply_wiki at cross-fire.org
Mon Nov 30 01:51:53 CST 2015


A page in your DokuWiki was added or changed. Here are the details:

Date        : 2015/11/30 01:51
User        : partmedia
Edit Summary: Reduce unnecessary verbosity

@@ -1,43 +1,16 @@
  ====== Client Scripting Interface ======
  
- The **client scripting interface** can be used to control a Crossfire client using an external program //(script)//. This interface can be used to extend the client or automate repetitive tasks (see [[client_side_scripting:scripts|sample scripts]]).
+ The **client scripting interface** can be used to control a Crossfire client using an external program (//script//). This interface can be used to extend the client or automate repetitive tasks (see [[client_side_scripting:scripts|sample scripts]]).
  
  The script is started from the client and communicates by reading information from standard input and writing commands to standard output. A full list of commands can be found below.
  
- ===== How do I run my script =====
  
- ==== C/++, Perl, Python, Bash, and others ====
+ ===== Getting Started =====
  
- Remember to ** chmod +x ** the script so that its executable.
- In the client type   **   script <pathname>    **
+ To run a script in the client, use the //script// command, which takes a path to the script to run. The script must be executable (//chmod +x// with an appropriate shebang). For some languages, it may be necessary to write a wrapper script to execute the actual program.
  
- The script should start.
- 
- 
- see also: [[#Windows-specific notes]]
- 
- ==== Java ====
- If you write you script in Java it gets a bit more tricky but no worries its not that hard.  
- We are going to create a shell script that will run our scripts in Java for us.
- 
-      #!/bin/bash
-      cd /dir/to/java.class
-      java $*
- 
- Remember to chmod +x this script so that its executable.
- Now to run your script this is all you have to do is  "script /path/to/bashScript blah"   blah being your .class file - .class and /path/to/bashScript being the executable bash script.
- 
- ===== Pipes, stdout, stdin =====
- (If this section causes you to consider puking by the second line, jump to the next section.)
- 
- The script is a program which is external to the client. It can be written in a wide range of languages. This can be C, Java, Perl, Python, Bash script, php, anything you can think about. How can this be possible? Let's take a look at what happens when you type "echo hello world" on a shell prompt. Sure it writes on your terminal "hello world". And if you are in a graphical shell prompt? It appears in the graphical console! Some process changed your request of writing to screen to a complex process of //get some system font// and //render the line in the specified window at the specified position//. All this because when you ask to "write hello world to screen" you ask, really, to "write hello world to the standard output device". This standard output device is called stdout. There is also the stdin, which most of the time is your keyboard and stderr, the standard error device being most of the time the same as stdout.\\  
- \\ 
- Ok, and now? Now what we use is exactly the same trick as the graphical console. when the client runs a script, it changes the script's stdin and replace the keyboard input with it's own orders (using a pipe). And it changes the stdout so instead of writing to screen, the script sends data to the client (using another pipe). And this is how any language can be used. Because every language can write to the screen and read from the keyboard!
- 
- ===== First Script =====
- 
- Learn to say hello
+ ==== Hello World ====
  
  Here we go for the first script. We will do quite simple things. We will ask our character to say "hello world" around. The script will be written in C because we simply need to choose a language. The script is quite simple:
  
    #include <stdio.h>


IP-Address  : 169.229.74.131
Hostname    : fre-74-131.ResHall.Berkeley.EDU
Old Revision: http://wiki.metalforge.net/dokuwiki/doku.php/client_side_scripting:client_scripting_interface-basic_howto?rev=1448866673
New Revision: http://wiki.metalforge.net/dokuwiki/doku.php/client_side_scripting:client_scripting_interface-basic_howto

-- 
This mail was generated by DokuWiki at
http://wiki.metalforge.net/dokuwiki/



More information about the crossfire-wiki mailing list