--- deliantra/server/lib/cf.pm 2006/07/20 22:03:36 1.26 +++ deliantra/server/lib/cf.pm 2006/07/21 00:51:39 1.27 @@ -16,6 +16,7 @@ our @EVENT; our %PROP_TYPE; our %PROP_IDX; +our $LIBDIR = maps_directory "perl"; BEGIN { @EVENT = map lc, @EVENT; @@ -232,14 +233,47 @@ warn "reloading...\n"; eval { + # 1. cancel all watchers $_->cancel for Event::all_watchers; - unload_extension $_ for @exts; + # 2. unload all extensions + for (@exts) { + $who->message ("unloading <$_>"); + unload_extension $_; + } + + # 3. unload all modules loaded from $LIBDIR + while (my ($k, $v) = each %INC) { + next unless $v =~ /^\Q$LIBDIR\E\/.*\.pm$/; + + $who->message ("removing <$k>"); + delete $INC{$k}; + + $k =~ s/\.pm$//; + $k =~ s/\//::/g; + + if (my $cb = $k->can ("unload_module")) { + $cb->(); + } + + Symbol::delete_package $k; + } + + # 4. get rid of ext::, as good as possible + Symbol::delete_package "ext::$_" + for qw(cf::object cf::object::map cf::object::player cf::player cf::map cf::party cf::region); + + # 5. remove register_script_function callbacks + # TODO + + # 6. unload cf.pm "a bit" delete $INC{"cf.pm"}; # don't, removes xs symbols, too #Symbol::delete_package __PACKAGE__; + # 7. reload cf.pm + $who->message ("reloading cf.pm"); require cf; }; warn $@ if $@; @@ -386,7 +420,7 @@ # here we export the classes and methods available to script code for ( - ["cf::object" => qw(contr)], + ["cf::object" => qw(contr pay_amount pay_player)], ["cf::object::player" => qw(player)], ["cf::player" => qw(peaceful)], ) { @@ -433,7 +467,7 @@ register "", __PACKAGE__; -unshift @INC, maps_directory "perl"; +unshift @INC, $LIBDIR; load_extensions;