Site Tools


ruby_command
no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


ruby_command [2007/02/20 03:54] (current) – created - external edit 127.0.0.1
Line 1: Line 1:
 +#$EPIC: ruby_command.txt,v 1.3 2007/02/20 03:54:29 jnelson Exp $
 +======Synopsis:======
 +[[ruby_command|ruby]] {//ruby statement//}
 +
 +======Purpose:======
 +If the client was linked with an embedded ruby interpreter, the //ruby 
 +statement//
 +shall be executed by ruby.  If the client was not linked against ruby, then no
 +action shall take place.
 +
 +Although every //ruby statement// resolves to a (ruby) scalar value, that
 +(ruby) scalar value is discarded when you run it this way.
 +
 +If the //ruby statement// has an error, the result is undefined, but usually
 +an error message is output to the window.
 +
 +Remember that the insides of {}s are protected from ircII expansion, so if
 +you want to pass ircII values into your ruby script, you do best to export
 +the value to ruby using $[[ruby function]]() first.  The insides of the {}
 +should be a literal segment of ruby code.
 +
 +You can call back to the client from ruby:
 +|EPIC.echo(string) | Output something on the epic window. |
 +|EPIC.say(string)  | Output something with [[set banner|banner]] on the epic window. |
 +|EPIC.cmd(string)  | Run "string" without $-expansion |
 +|EPIC.eval(string) | Run "string" with $-expansion |
 +|EPIC.expr(string) | Return value of epic expression "string" |
 +|EPIC.call(string) | Call an epic function: string must be of the form "name(args)". $* will expand to the empty string. |
 +
 +You are permitted to register ruby END blocks.  They will run when epic
 +initiates shutdown procedures.
 +
 +It is important to remember that to ruby, everything in ircII is a String 
 +object.  When you use EPIC.expr(), you get a String back.  If you know that
 +the value contains an integer, you must cast it (with .to_i).
 +
 +It is important to remember that ruby is less tolerant of rogue semicolons
 +than ircII is.  You do not want to mix the standard loader with ruby.  Use
 +the PF loader for everything, to avoid unnecessary insertion of semicolons.
 +
 +======Examples:======
 +<file>
 +Assign to the epic variable $epicvar the value of the ruby variable "rubyvar"
 + RUBY { EPIC.expr("epicvar=[#{rubyvar}]") }
 +
 +Assign to the ruby variable "rubyvar" the value of the epic variable "epicvar"
 + RUBY { rubyvar = EPIC.expr("epicvar") }
 +
 +Run /EPIC_ALIAS five times, passing it each number 1 to 5.
 + RUBY {
 + 1.upto(5) {|x|
 + EPIC.cmd("epic_alias #{x}")
 + }
 + }
 +
 +Iterate over each item in ruby collection, passing each value to epic alias:
 + RUBY {
 + something.each {|x|
 + EPIC.cmd("epiccmd #{x}")
 + }
 + }
 +
 +Assign a value to a local variable, manipulate it in ruby, and pass it back:
 + alias booya {
 + @ :epiclocal = 5
 + ruby {
 + rubyvar = EPIC.expr("epiclocal").to_i
 + rubyvar = rubyvar + 1
 + EPIC.expr("epiclocal = [#{rubyvar}]")
 + }
 + echo $epiclocal
 + }
 +</file>
 +
 +======History:======
 +The [[ruby command]] first appeared in EPIC5-0.3.1.
  
ruby_command.txt · Last modified: 2007/02/20 03:54 by 127.0.0.1