1 | package cf; |
1 | package cf; |
2 | |
2 | |
3 | use Symbol; |
3 | use Symbol; |
4 | use List::Util; |
4 | use List::Util; |
5 | use Storable; |
5 | use Storable; |
|
|
6 | |
6 | use Event; |
7 | use Event; |
|
|
8 | $Event::Eval = 1; # no idea why this is required, but it is |
7 | |
9 | |
8 | use strict; |
10 | use strict; |
9 | |
11 | |
10 | our %COMMAND; |
12 | our %COMMAND; |
11 | our @EVENT; |
13 | our @EVENT; |
… | |
… | |
167 | |
169 | |
168 | sub unload_extension { |
170 | sub unload_extension { |
169 | my ($pkg) = @_; |
171 | my ($pkg) = @_; |
170 | |
172 | |
171 | warn "removing extension $pkg\n"; |
173 | warn "removing extension $pkg\n"; |
|
|
174 | |
|
|
175 | if (my $cb = $pkg->can ("on_unload")) { |
|
|
176 | $cb->($pkg); |
|
|
177 | } |
172 | |
178 | |
173 | # remove hooks |
179 | # remove hooks |
174 | for my $idx (0 .. $#EVENT) { |
180 | for my $idx (0 .. $#EVENT) { |
175 | delete $hook[$idx]{$pkg}; |
181 | delete $hook[$idx]{$pkg}; |
176 | } |
182 | } |
… | |
… | |
214 | if ($who->flag (FLAG_WIZ)) { |
220 | if ($who->flag (FLAG_WIZ)) { |
215 | $who->message ("reloading..."); |
221 | $who->message ("reloading..."); |
216 | |
222 | |
217 | warn "reloading...\n"; |
223 | warn "reloading...\n"; |
218 | eval { |
224 | eval { |
|
|
225 | $_->cancel for Event::all_watchers; |
|
|
226 | |
219 | unload_extension $_ for @exts; |
227 | unload_extension $_ for @exts; |
220 | delete $INC{"cf.pm"}; |
228 | delete $INC{"cf.pm"}; |
221 | |
229 | |
222 | # don't, removes xs symbols, too |
230 | # don't, removes xs symbols, too |
223 | #Symbol::delete_package $pkg; |
231 | #Symbol::delete_package __PACKAGE__; |
224 | |
232 | |
225 | require cf; |
233 | require cf; |
226 | }; |
234 | }; |
227 | warn $@ if $@; |
235 | warn $@ if $@; |
228 | $who->message ($@) if $@; |
236 | $who->message ($@) if $@; |
… | |
… | |
339 | for grep %$_, $ob, $ob->inv; |
347 | for grep %$_, $ob, $ob->inv; |
340 | |
348 | |
341 | unlink "$path.cfperl";#d##TODO#remove |
349 | unlink "$path.cfperl";#d##TODO#remove |
342 | }; |
350 | }; |
343 | |
351 | |
|
|
352 | ############################################################################# |
|
|
353 | # core extensions - in perl |
|
|
354 | |
|
|
355 | # rough implementation of a future "reply" method that works |
|
|
356 | # with dialog boxes. |
|
|
357 | sub cf::object::player::reply($$;$) { |
|
|
358 | my ($self, $msg, $flags) = @_; |
|
|
359 | |
|
|
360 | $flags = cf::NDI_WHITE unless @_ >= 3; |
|
|
361 | |
|
|
362 | $self->message ($msg, $flags); |
|
|
363 | } |
|
|
364 | |
|
|
365 | ############################################################################# |
|
|
366 | # initialisation |
|
|
367 | |
344 | register "<global>", __PACKAGE__; |
368 | register "<global>", __PACKAGE__; |
345 | |
369 | |
346 | unshift @INC, maps_directory "perl"; |
370 | unshift @INC, maps_directory "perl"; |
347 | |
371 | |
348 | load_extensions; |
372 | load_extensions; |