ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/eval.ext
Revision: 1.2
Committed: Fri Mar 31 20:43:18 2006 UTC (18 years, 1 month ago) by root
Branch: MAIN
Changes since 1.1: +18 -2 lines
Log Message:
improved eval plugin

File Contents

# User Rev Content
1 root 1.1 #! perl
2    
3     # generic perl code evaluator
4    
5 root 1.2 sub eval_event {
6     my ($event, $args, @args) = @_;
7    
8     my $code = $event->message;
9     my $who = eval { $event->environment->name } || "<unknown>";
10    
11     my $rv = eval "my ($args) = \@args;\n"
12     . "#line 1 \"$who\"\n"
13     . $code;
14    
15     warn $@ if $@;
16    
17     $rv
18     }
19    
20 root 1.1 # currently say only
21     sub on_say {
22     my ($event) = @_;
23 root 1.2 my ($event, $who, $msg, $options) = @$event{qw(event who message options)};
24 root 1.1
25     local $_ = $msg;
26 root 1.2
27     eval_event $event, '$who, $msg, $options', $who, $msg, $options
28 root 1.1 }