programming
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
| — | programming [2006/08/29 20:18] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ======Programming in EPIC====== | ||
| + | |||
| + | This short (very short) document describes EPIC's programming language (some | ||
| + | would argue it's but a scripting language) and how to use it. | ||
| + | |||
| + | The first thing to remember about scripts is that command characters are | ||
| + | not required for commands! | ||
| + | makes more work for the client when parsing the command. | ||
| + | course, an exception to this rule (but only one). Because the client allows | ||
| + | commands to be overloaded by aliases, there needs to be a way to access the | ||
| + | original command. | ||
| + | instance: | ||
| + | |||
| + | alias mode { | ||
| + | if ( (index(#& | ||
| + | // | ||
| + | } { | ||
| + | // | ||
| + | } | ||
| + | } | ||
| + | |||
| + | The above alias overloads the built-in [[MODE]] command. | ||
| + | the first argument passed was a channel name or your own nickname. | ||
| + | it executes the real [[MODE]] command using the arguments given. | ||
| + | executes the real [[MODE]] command for the current channel. | ||
| + | user can change the command character, the / character is always accepted as | ||
| + | a command character in a script. | ||
| + | hack as you do in ircII -- using two slashes works just fine in EPIC. | ||
| + | |||
| + | Good: | ||
| + | Bad: | ||
| + | |||
| + | Certain characters have special meaning in scripts and inside certain | ||
| + | commands that they don't necessarily have on the input line. The semicolon | ||
| + | (;), when used inside a {} command construct (from an alias, key binding, | ||
| + | hook, timer action, etc.), is a command separator. | ||
| + | |||
| + | alias blah { | ||
| + | on hook * echo hooked: $*;echo oops! | ||
| + | } | ||
| + | |||
| + | When the /blah alias is run, " | ||
| + | want that. We wanted it to be displayed whenever the HOOK command was | ||
| + | called. | ||
| + | that you want to be considered as one command, like so: | ||
| + | |||
| + | alias blah { | ||
| + | on hook * {echo hooked: $*;echo oops!} | ||
| + | } | ||
| + | |||
| + | The backslash (\) character " | ||
| + | not on the input line). | ||
| + | meaning that it might have (such as semicolons, or newlines, or double-quotes). | ||
| + | In addition to this, if the backslash character is the last character on a | ||
| + | line (no spaces after it -- nothing at all) then the backslash character will | ||
| + | do line-continuation: | ||
| + | |||
| + | if ( foo == 1 && \ | ||
| + | bar == 2 ) { ... } | ||
| + | |||
| + | behaves exactly as if you had done: | ||
| + | |||
| + | if ( foo == 1 && | ||
| + | |||
| + | |||
| + | In general, no matter what the circumstance, | ||
| + | within parenthesis, | ||
| + | expansion until it is actually needed. | ||
| + | brace thing to work in the above example: | ||
| + | |||
| + | alias blah { | ||
| + | on hook * {echo hooked: $*;echo oops!} | ||
| + | } | ||
| + | |||
| + | Unlike ircII, you can use curly braces anywhere you want in EPIC in order | ||
| + | to protect early expansion. | ||
| + | |||
| + | Speaking of quoting characters, the client' | ||
| + | confusing. In general, everything works as described above; quote | ||
| + | special characters to use them in text context. | ||
| + | change when the client needs to parse a command more than once. | ||
| + | [[userhost command|USERHOST]] is a classic example of this. Let's say | ||
| + | we've created this alias: | ||
| + | |||
| + | alias foo userhost $0 -cmd echo ($*) | ||
| + | |||
| + | That won't do at all, because both $expandos are parsed once, before the | ||
| + | command is even executed, which isn't what we want. So we need to do some | ||
| + | quoting on the -cmd part: | ||
| + | |||
| + | alias foo userhost $0 -cmd echo \($$*\) | ||
| + | |||
| + | Note that we quoted the ' | ||
| + | that expands to a single ' | ||
| + | but the $$ expando is faster. | ||
| + | Because the parentheses cause the whole statement to be parsed twice, so | ||
| + | we're right back where we started. | ||
| + | to the parentheses: | ||
| + | |||
| + | alias foo userhost $0 -cmd echo \\\($$*\\\) | ||
| + | |||
| + | After the initial parse run, the parenthesis are still quoted, because ' | ||
| + | expands to ' | ||
| + | command is executed, the [[ECHO]] command is then parsed, this time correctly. | ||
| + | |||
| + | Other miscellaneous tips: | ||
| + | |||
| + | - Use variable and alias structures. | ||
| + | - Indent your code consistently. | ||
| + | - Comment your code. So you'll know what you did a year from now. | ||
| + | - Use serial numbered hooks whenever possible. | ||
| + | - For server output, use the " | ||
| + | - Read the client documentation! :) | ||
| + | |||
| + | Refer to Section 5 of these helpfiles for information about specific | ||
| + | commands. | ||
| + | |||
programming.txt · Last modified: 2006/08/29 20:18 by 127.0.0.1
