1 |
root |
1.1 |
package cf; |
2 |
|
|
|
3 |
|
|
use Symbol; |
4 |
|
|
use List::Util; |
5 |
root |
1.6 |
use Storable; |
6 |
root |
1.23 |
use Opcode; |
7 |
|
|
use Safe; |
8 |
|
|
use Safe::Hole; |
9 |
root |
1.19 |
|
10 |
root |
1.18 |
use Event; |
11 |
root |
1.19 |
$Event::Eval = 1; # no idea why this is required, but it is |
12 |
root |
1.1 |
|
13 |
|
|
use strict; |
14 |
|
|
|
15 |
|
|
our %COMMAND; |
16 |
|
|
our @EVENT; |
17 |
|
|
our %PROP_TYPE; |
18 |
|
|
our %PROP_IDX; |
19 |
root |
1.27 |
our $LIBDIR = maps_directory "perl"; |
20 |
root |
1.1 |
|
21 |
|
|
BEGIN { |
22 |
|
|
@EVENT = map lc, @EVENT; |
23 |
|
|
|
24 |
|
|
*CORE::GLOBAL::warn = sub { |
25 |
|
|
my $msg = join "", @_; |
26 |
|
|
$msg .= "\n" |
27 |
|
|
unless $msg =~ /\n$/; |
28 |
|
|
|
29 |
|
|
print STDERR "cfperl: $msg"; |
30 |
|
|
LOG llevError, "cfperl: $msg"; |
31 |
|
|
}; |
32 |
|
|
} |
33 |
|
|
|
34 |
root |
1.9 |
my %ignore_set = (MAP_PROP_PATH => 1); # I hate the plug-in api. Deeply! |
35 |
|
|
|
36 |
root |
1.1 |
# generate property mutators |
37 |
|
|
sub prop_gen { |
38 |
|
|
my ($prefix, $class) = @_; |
39 |
|
|
|
40 |
|
|
no strict 'refs'; |
41 |
|
|
|
42 |
|
|
for my $prop (keys %PROP_TYPE) { |
43 |
|
|
$prop =~ /^\Q$prefix\E_(.*$)/ or next; |
44 |
|
|
my $sub = lc $1; |
45 |
|
|
|
46 |
|
|
my $type = $PROP_TYPE{$prop}; |
47 |
|
|
my $idx = $PROP_IDX {$prop}; |
48 |
|
|
|
49 |
|
|
*{"$class\::get_$sub"} = *{"$class\::$sub"} = sub { |
50 |
|
|
$_[0]->get_property ($type, $idx) |
51 |
|
|
}; |
52 |
|
|
|
53 |
|
|
*{"$class\::set_$sub"} = sub { |
54 |
|
|
$_[0]->set_property ($type, $idx, $_[1]); |
55 |
root |
1.9 |
} unless $ignore_set{$prop}; |
56 |
root |
1.1 |
} |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
# auto-generate most of the API |
60 |
|
|
|
61 |
|
|
prop_gen OBJECT_PROP => "cf::object"; |
62 |
|
|
# CFAPI_OBJECT_ANIMATION? |
63 |
|
|
prop_gen PLAYER_PROP => "cf::object::player"; |
64 |
|
|
|
65 |
|
|
prop_gen MAP_PROP => "cf::map"; |
66 |
|
|
prop_gen ARCH_PROP => "cf::arch"; |
67 |
|
|
|
68 |
|
|
# guessed hierarchies |
69 |
|
|
|
70 |
root |
1.25 |
@ext::cf::object::player::ISA = @cf::object::player::ISA = 'cf::object'; |
71 |
|
|
@ext::cf::object::map::ISA = @cf::object::map::ISA = 'cf::object'; |
72 |
|
|
|
73 |
|
|
# we bless all objects into derived classes to force a method lookup |
74 |
|
|
# within the Safe compartment. |
75 |
elmex |
1.30 |
for my $pkg (qw(cf::object cf::object::map cf::object::player cf::player cf::map cf::party cf::region cf::arch)) { |
76 |
root |
1.25 |
no strict 'refs'; |
77 |
|
|
@{"ext::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; |
78 |
|
|
} |
79 |
root |
1.1 |
|
80 |
root |
1.18 |
$Event::DIED = sub { |
81 |
|
|
warn "error in event callback: @_"; |
82 |
|
|
}; |
83 |
|
|
|
84 |
root |
1.5 |
my %ext_pkg; |
85 |
root |
1.1 |
my @exts; |
86 |
|
|
my @hook; |
87 |
|
|
my %command; |
88 |
root |
1.15 |
my %extcmd; |
89 |
root |
1.1 |
|
90 |
|
|
sub inject_event { |
91 |
root |
1.14 |
my $extension = shift; |
92 |
|
|
my $event_code = shift; |
93 |
root |
1.1 |
|
94 |
root |
1.14 |
my $cb = $hook[$event_code]{$extension} |
95 |
root |
1.5 |
or return; |
96 |
|
|
|
97 |
root |
1.14 |
&$cb |
98 |
root |
1.5 |
} |
99 |
|
|
|
100 |
|
|
sub inject_global_event { |
101 |
root |
1.12 |
my $event = shift; |
102 |
root |
1.5 |
|
103 |
root |
1.12 |
my $cb = $hook[$event] |
104 |
root |
1.1 |
or return; |
105 |
|
|
|
106 |
root |
1.12 |
List::Util::max map &$_, values %$cb |
107 |
root |
1.1 |
} |
108 |
|
|
|
109 |
|
|
sub inject_command { |
110 |
|
|
my ($name, $obj, $params) = @_; |
111 |
|
|
|
112 |
|
|
for my $cmd (@{ $command{$name} }) { |
113 |
|
|
$cmd->[1]->($obj, $params); |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
-1 |
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
sub register_command { |
120 |
|
|
my ($name, $time, $cb) = @_; |
121 |
|
|
|
122 |
|
|
my $caller = caller; |
123 |
root |
1.16 |
#warn "registering command '$name/$time' to '$caller'"; |
124 |
root |
1.4 |
|
125 |
root |
1.1 |
push @{ $command{$name} }, [$time, $cb, $caller]; |
126 |
|
|
$COMMAND{"$name\000"} = List::Util::max map $_->[0], @{ $command{$name} }; |
127 |
|
|
} |
128 |
|
|
|
129 |
root |
1.16 |
sub register_extcmd { |
130 |
|
|
my ($name, $cb) = @_; |
131 |
|
|
|
132 |
|
|
my $caller = caller; |
133 |
|
|
#warn "registering extcmd '$name' to '$caller'"; |
134 |
|
|
|
135 |
|
|
$extcmd{$name} = [$cb, $caller]; |
136 |
|
|
} |
137 |
|
|
|
138 |
root |
1.6 |
sub register { |
139 |
|
|
my ($base, $pkg) = @_; |
140 |
|
|
|
141 |
|
|
for my $idx (0 .. $#EVENT) { |
142 |
|
|
if (my $ref = $pkg->can ("on_$EVENT[$idx]")) { |
143 |
root |
1.16 |
#warn "registering $EVENT[$idx] hook to '$pkg'\n"; |
144 |
root |
1.6 |
$hook[$idx]{$base} = $ref; |
145 |
|
|
} |
146 |
|
|
} |
147 |
|
|
} |
148 |
|
|
|
149 |
root |
1.1 |
sub load_extension { |
150 |
|
|
my ($path) = @_; |
151 |
|
|
|
152 |
|
|
$path =~ /([^\/\\]+)\.ext$/ or die "$path"; |
153 |
root |
1.5 |
my $base = $1; |
154 |
root |
1.1 |
my $pkg = $1; |
155 |
|
|
$pkg =~ s/[^[:word:]]/_/g; |
156 |
|
|
$pkg = "cf::ext::$pkg"; |
157 |
|
|
|
158 |
|
|
warn "loading '$path' into '$pkg'\n"; |
159 |
|
|
|
160 |
|
|
open my $fh, "<:utf8", $path |
161 |
|
|
or die "$path: $!"; |
162 |
|
|
|
163 |
|
|
my $source = |
164 |
|
|
"package $pkg; use strict; use utf8;\n" |
165 |
|
|
. "#line 1 \"$path\"\n{\n" |
166 |
|
|
. (do { local $/; <$fh> }) |
167 |
|
|
. "\n};\n1"; |
168 |
|
|
|
169 |
|
|
eval $source |
170 |
|
|
or die "$path: $@"; |
171 |
|
|
|
172 |
|
|
push @exts, $pkg; |
173 |
root |
1.5 |
$ext_pkg{$base} = $pkg; |
174 |
root |
1.1 |
|
175 |
root |
1.6 |
# no strict 'refs'; |
176 |
root |
1.23 |
# @{"$pkg\::ISA"} = ext::; |
177 |
root |
1.1 |
|
178 |
root |
1.6 |
register $base, $pkg; |
179 |
root |
1.1 |
} |
180 |
|
|
|
181 |
|
|
sub unload_extension { |
182 |
|
|
my ($pkg) = @_; |
183 |
|
|
|
184 |
|
|
warn "removing extension $pkg\n"; |
185 |
|
|
|
186 |
root |
1.21 |
if (my $cb = $pkg->can ("on_unload")) { |
187 |
|
|
$cb->($pkg); |
188 |
|
|
} |
189 |
|
|
|
190 |
root |
1.1 |
# remove hooks |
191 |
|
|
for my $idx (0 .. $#EVENT) { |
192 |
|
|
delete $hook[$idx]{$pkg}; |
193 |
|
|
} |
194 |
|
|
|
195 |
|
|
# remove commands |
196 |
|
|
for my $name (keys %command) { |
197 |
|
|
my @cb = grep $_->[2] ne $pkg, @{ $command{$name} }; |
198 |
|
|
|
199 |
|
|
if (@cb) { |
200 |
|
|
$command{$name} = \@cb; |
201 |
|
|
$COMMAND{"$name\000"} = List::Util::max map $_->[0], @cb; |
202 |
|
|
} else { |
203 |
|
|
delete $command{$name}; |
204 |
|
|
delete $COMMAND{"$name\000"}; |
205 |
|
|
} |
206 |
|
|
} |
207 |
|
|
|
208 |
root |
1.15 |
# remove extcmds |
209 |
root |
1.16 |
for my $name (grep $extcmd{$_}[1] eq $pkg, keys %extcmd) { |
210 |
|
|
delete $extcmd{$name}; |
211 |
root |
1.15 |
} |
212 |
|
|
|
213 |
root |
1.1 |
Symbol::delete_package $pkg; |
214 |
|
|
} |
215 |
|
|
|
216 |
|
|
sub load_extensions { |
217 |
|
|
my $LIBDIR = maps_directory "perl"; |
218 |
|
|
|
219 |
|
|
for my $ext (<$LIBDIR/*.ext>) { |
220 |
root |
1.3 |
next unless -r $ext; |
221 |
root |
1.2 |
eval { |
222 |
|
|
load_extension $ext; |
223 |
|
|
1 |
224 |
|
|
} or warn "$ext not loaded: $@"; |
225 |
root |
1.1 |
} |
226 |
|
|
} |
227 |
|
|
|
228 |
|
|
register_command "perl-reload", 0, sub { |
229 |
|
|
my ($who, $arg) = @_; |
230 |
|
|
|
231 |
|
|
if ($who->flag (FLAG_WIZ)) { |
232 |
root |
1.3 |
$who->message ("reloading..."); |
233 |
|
|
|
234 |
root |
1.1 |
warn "reloading...\n"; |
235 |
root |
1.4 |
eval { |
236 |
root |
1.27 |
# 1. cancel all watchers |
237 |
root |
1.20 |
$_->cancel for Event::all_watchers; |
238 |
|
|
|
239 |
root |
1.27 |
# 2. unload all extensions |
240 |
|
|
for (@exts) { |
241 |
|
|
$who->message ("unloading <$_>"); |
242 |
|
|
unload_extension $_; |
243 |
|
|
} |
244 |
|
|
|
245 |
|
|
# 3. unload all modules loaded from $LIBDIR |
246 |
|
|
while (my ($k, $v) = each %INC) { |
247 |
|
|
next unless $v =~ /^\Q$LIBDIR\E\/.*\.pm$/; |
248 |
|
|
|
249 |
|
|
$who->message ("removing <$k>"); |
250 |
|
|
delete $INC{$k}; |
251 |
|
|
|
252 |
|
|
$k =~ s/\.pm$//; |
253 |
|
|
$k =~ s/\//::/g; |
254 |
|
|
|
255 |
|
|
if (my $cb = $k->can ("unload_module")) { |
256 |
|
|
$cb->(); |
257 |
|
|
} |
258 |
|
|
|
259 |
|
|
Symbol::delete_package $k; |
260 |
|
|
} |
261 |
|
|
|
262 |
|
|
# 4. get rid of ext::, as good as possible |
263 |
|
|
Symbol::delete_package "ext::$_" |
264 |
|
|
for qw(cf::object cf::object::map cf::object::player cf::player cf::map cf::party cf::region); |
265 |
|
|
|
266 |
|
|
# 5. remove register_script_function callbacks |
267 |
|
|
# TODO |
268 |
|
|
|
269 |
|
|
# 6. unload cf.pm "a bit" |
270 |
root |
1.4 |
delete $INC{"cf.pm"}; |
271 |
|
|
|
272 |
|
|
# don't, removes xs symbols, too |
273 |
root |
1.21 |
#Symbol::delete_package __PACKAGE__; |
274 |
root |
1.4 |
|
275 |
root |
1.27 |
# 7. reload cf.pm |
276 |
|
|
$who->message ("reloading cf.pm"); |
277 |
root |
1.4 |
require cf; |
278 |
|
|
}; |
279 |
|
|
warn $@ if $@; |
280 |
|
|
$who->message ($@) if $@; |
281 |
root |
1.1 |
warn "reloaded\n"; |
282 |
root |
1.3 |
|
283 |
|
|
$who->message ("reloaded"); |
284 |
|
|
} else { |
285 |
|
|
$who->message ("Intruder Alert!"); |
286 |
root |
1.1 |
} |
287 |
|
|
}; |
288 |
|
|
|
289 |
root |
1.8 |
############################################################################# |
290 |
root |
1.28 |
# utility functions |
291 |
|
|
|
292 |
|
|
use JSON::Syck (); # TODO# replace by JSON::PC once working |
293 |
|
|
|
294 |
|
|
sub from_json($) { |
295 |
root |
1.29 |
$JSON::Syck::ImplicitUnicode = 1; # work around JSON::Syck bugs |
296 |
root |
1.28 |
JSON::Syck::Load $_[0] |
297 |
|
|
} |
298 |
|
|
|
299 |
|
|
sub to_json($) { |
300 |
root |
1.29 |
$JSON::Syck::ImplicitUnicode = 0; # work around JSON::Syck bugs |
301 |
root |
1.28 |
JSON::Syck::Dump $_[0] |
302 |
|
|
} |
303 |
|
|
|
304 |
|
|
############################################################################# |
305 |
|
|
# extcmd framework, basically convert ext <msg> |
306 |
root |
1.15 |
# into pkg::->on_extcmd_arg1 (...) while shortcutting a few |
307 |
|
|
|
308 |
|
|
sub on_extcmd { |
309 |
|
|
my ($pl, $buf) = @_; |
310 |
|
|
|
311 |
root |
1.28 |
my $msg = eval { from_json $buf }; |
312 |
|
|
|
313 |
|
|
if (ref $msg) { |
314 |
|
|
if (my $cb = $extcmd{$msg->{msgtype}}) { |
315 |
|
|
if (my %reply = $cb->[0]->($pl, $msg)) { |
316 |
|
|
$pl->ext_reply ($msg->{msgid}, %reply); |
317 |
|
|
} |
318 |
|
|
} |
319 |
|
|
} else { |
320 |
|
|
warn "player " . ($pl->ob->name) . " sent unparseable ext message: <$buf>\n"; |
321 |
|
|
} |
322 |
root |
1.15 |
|
323 |
root |
1.28 |
1 |
324 |
root |
1.15 |
} |
325 |
|
|
|
326 |
|
|
############################################################################# |
327 |
root |
1.8 |
# load/save/clean perl data associated with a map |
328 |
|
|
|
329 |
root |
1.7 |
*on_mapclean = sub { |
330 |
root |
1.13 |
my ($map) = @_; |
331 |
root |
1.7 |
|
332 |
|
|
my $path = $map->tmpname; |
333 |
|
|
defined $path or return; |
334 |
|
|
|
335 |
|
|
unlink "$path.cfperl"; |
336 |
|
|
}; |
337 |
|
|
|
338 |
root |
1.6 |
*on_mapin = |
339 |
|
|
*on_mapload = sub { |
340 |
root |
1.13 |
my ($map) = @_; |
341 |
root |
1.6 |
|
342 |
|
|
my $path = $map->tmpname; |
343 |
|
|
$path = $map->path unless defined $path; |
344 |
|
|
|
345 |
|
|
open my $fh, "<:raw", "$path.cfperl" |
346 |
|
|
or return; # no perl data |
347 |
|
|
|
348 |
|
|
my $data = Storable::thaw do { local $/; <$fh> }; |
349 |
|
|
|
350 |
|
|
$data->{version} <= 1 |
351 |
|
|
or return; # too new |
352 |
|
|
|
353 |
|
|
$map->_set_obs ($data->{obs}); |
354 |
|
|
}; |
355 |
|
|
|
356 |
|
|
*on_mapout = sub { |
357 |
root |
1.13 |
my ($map) = @_; |
358 |
root |
1.6 |
|
359 |
|
|
my $path = $map->tmpname; |
360 |
|
|
$path = $map->path unless defined $path; |
361 |
|
|
|
362 |
|
|
my $obs = $map->_get_obs; |
363 |
|
|
|
364 |
|
|
if (defined $obs) { |
365 |
|
|
open my $fh, ">:raw", "$path.cfperl" |
366 |
|
|
or die "$path.cfperl: $!"; |
367 |
|
|
|
368 |
root |
1.8 |
stat $path; |
369 |
|
|
|
370 |
|
|
print $fh Storable::nfreeze { |
371 |
|
|
size => (stat _)[7], |
372 |
|
|
time => (stat _)[9], |
373 |
|
|
version => 1, |
374 |
|
|
obs => $obs, |
375 |
|
|
}; |
376 |
|
|
|
377 |
|
|
chmod SAVE_MODE, "$path.cfperl"; # very racy, but cf-compatible *g* |
378 |
|
|
} else { |
379 |
|
|
unlink "$path.cfperl"; |
380 |
|
|
} |
381 |
|
|
}; |
382 |
|
|
|
383 |
|
|
############################################################################# |
384 |
|
|
# load/save perl data associated with player->ob objects |
385 |
|
|
|
386 |
|
|
*on_player_load = sub { |
387 |
root |
1.13 |
my ($ob, $path) = @_; |
388 |
root |
1.8 |
|
389 |
root |
1.11 |
for my $o ($ob, $ob->inv) { |
390 |
|
|
if (my $value = $o->get_ob_key_value ("_perl_data")) { |
391 |
|
|
$o->set_ob_key_value ("_perl_data"); |
392 |
|
|
|
393 |
|
|
%$o = %{ Storable::thaw pack "H*", $value }; |
394 |
|
|
} |
395 |
|
|
} |
396 |
root |
1.8 |
}; |
397 |
|
|
|
398 |
|
|
*on_player_save = sub { |
399 |
root |
1.13 |
my ($ob, $path) = @_; |
400 |
root |
1.8 |
|
401 |
root |
1.11 |
$_->set_ob_key_value (_perl_data => unpack "H*", Storable::nfreeze $_) |
402 |
|
|
for grep %$_, $ob, $ob->inv; |
403 |
root |
1.6 |
}; |
404 |
|
|
|
405 |
root |
1.22 |
############################################################################# |
406 |
|
|
# core extensions - in perl |
407 |
|
|
|
408 |
root |
1.23 |
=item cf::player::exists $login |
409 |
|
|
|
410 |
|
|
Returns true when the given account exists. |
411 |
|
|
|
412 |
|
|
=cut |
413 |
|
|
|
414 |
|
|
sub cf::player::exists($) { |
415 |
|
|
cf::player::find $_[0] |
416 |
|
|
or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; |
417 |
|
|
} |
418 |
|
|
|
419 |
root |
1.28 |
=item $player->reply ($npc, $msg[, $flags]) |
420 |
|
|
|
421 |
|
|
Sends a message to the player, as if the npc C<$npc> replied. C<$npc> |
422 |
|
|
can be C<undef>. Does the right thing when the player is currently in a |
423 |
|
|
dialogue with the given NPC character. |
424 |
|
|
|
425 |
|
|
=cut |
426 |
|
|
|
427 |
root |
1.22 |
# rough implementation of a future "reply" method that works |
428 |
|
|
# with dialog boxes. |
429 |
root |
1.23 |
sub cf::object::player::reply($$$;$) { |
430 |
|
|
my ($self, $npc, $msg, $flags) = @_; |
431 |
|
|
|
432 |
|
|
$flags = cf::NDI_BROWN | cf::NDI_UNIQUE unless @_ >= 4; |
433 |
root |
1.22 |
|
434 |
root |
1.24 |
if ($self->{record_replies}) { |
435 |
|
|
push @{ $self->{record_replies} }, [$npc, $msg, $flags]; |
436 |
|
|
} else { |
437 |
|
|
$msg = $npc->name . " says: $msg" if $npc; |
438 |
|
|
$self->message ($msg, $flags); |
439 |
|
|
} |
440 |
root |
1.22 |
} |
441 |
|
|
|
442 |
root |
1.28 |
=item $player->ext_reply ($msgid, $msgtype, %msg) |
443 |
|
|
|
444 |
|
|
Sends an ext reply to the player. |
445 |
|
|
|
446 |
|
|
=cut |
447 |
|
|
|
448 |
|
|
sub cf::player::ext_reply($$$%) { |
449 |
|
|
my ($self, $id, %msg) = @_; |
450 |
|
|
|
451 |
|
|
$msg{msgid} = $id; |
452 |
|
|
|
453 |
|
|
$self->send ("ext " . to_json \%msg); |
454 |
|
|
} |
455 |
|
|
|
456 |
root |
1.22 |
############################################################################# |
457 |
root |
1.23 |
# map scripting support |
458 |
|
|
|
459 |
|
|
our $safe = new Safe "ext"; |
460 |
|
|
our $safe_hole = new Safe::Hole; |
461 |
|
|
|
462 |
|
|
$SIG{FPE} = 'IGNORE'; |
463 |
|
|
|
464 |
|
|
$safe->permit_only (Opcode::opset qw(:base_core :base_mem :base_orig :base_math sort time)); |
465 |
|
|
|
466 |
root |
1.25 |
# here we export the classes and methods available to script code |
467 |
|
|
|
468 |
|
|
for ( |
469 |
root |
1.27 |
["cf::object" => qw(contr pay_amount pay_player)], |
470 |
root |
1.25 |
["cf::object::player" => qw(player)], |
471 |
|
|
["cf::player" => qw(peaceful)], |
472 |
|
|
) { |
473 |
|
|
no strict 'refs'; |
474 |
|
|
my ($pkg, @funs) = @$_; |
475 |
|
|
*{"ext::$pkg\::$_"} = $safe_hole->wrap (\&{"$pkg\::$_"}) |
476 |
|
|
for @funs; |
477 |
|
|
} |
478 |
root |
1.23 |
|
479 |
|
|
sub safe_eval($;@) { |
480 |
|
|
my ($code, %vars) = @_; |
481 |
|
|
|
482 |
|
|
my $qcode = $code; |
483 |
|
|
$qcode =~ s/"/‟/g; # not allowed in #line filenames |
484 |
|
|
$qcode =~ s/\n/\\n/g; |
485 |
|
|
|
486 |
|
|
local $_; |
487 |
|
|
local @ext::cf::_safe_eval_args = values %vars; |
488 |
|
|
|
489 |
root |
1.25 |
$code = |
490 |
root |
1.23 |
"do {\n" |
491 |
|
|
. "my (" . (join ",", map "\$$_", keys %vars) . ") = \@cf::_safe_eval_args;\n" |
492 |
|
|
. "#line 0 \"{$qcode}\"\n" |
493 |
|
|
. $code |
494 |
|
|
. "\n}" |
495 |
root |
1.25 |
; |
496 |
|
|
|
497 |
|
|
sub_generation_inc; |
498 |
|
|
my @res = wantarray ? $safe->reval ($code) : scalar $safe->reval ($code); |
499 |
|
|
sub_generation_inc; |
500 |
|
|
|
501 |
|
|
wantarray ? @res : $res[0] |
502 |
root |
1.23 |
} |
503 |
|
|
|
504 |
|
|
sub register_script_function { |
505 |
|
|
my ($fun, $cb) = @_; |
506 |
|
|
|
507 |
|
|
no strict 'refs'; |
508 |
|
|
*{"ext::$fun"} = $safe_hole->wrap ($cb); |
509 |
|
|
} |
510 |
|
|
|
511 |
|
|
############################################################################# |
512 |
root |
1.22 |
# initialisation |
513 |
|
|
|
514 |
root |
1.6 |
register "<global>", __PACKAGE__; |
515 |
|
|
|
516 |
root |
1.27 |
unshift @INC, $LIBDIR; |
517 |
root |
1.17 |
|
518 |
root |
1.1 |
load_extensions; |
519 |
|
|
|
520 |
|
|
1 |
521 |
|
|
|