ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf.pm
(Generate patch)

Comparing deliantra/server/lib/cf.pm (file contents):
Revision 1.44 by root, Sat Aug 26 08:44:06 2006 UTC vs.
Revision 1.62 by root, Fri Sep 8 16:51:44 2006 UTC

11use Event; 11use Event;
12$Event::Eval = 1; # no idea why this is required, but it is 12$Event::Eval = 1; # no idea why this is required, but it is
13 13
14use strict; 14use strict;
15 15
16_reload_1;
17
16our %COMMAND = (); 18our %COMMAND = ();
17our @EVENT; 19our @EVENT;
18our @PLUGIN_EVENT;
19our %PROP_TYPE;
20our %PROP_IDX;
21our $LIBDIR = maps_directory "perl"; 20our $LIBDIR = maps_directory "perl";
22 21
23our $TICK = MAX_TIME * 1e-6; 22our $TICK = MAX_TIME * 1e-6;
24our $TICK_WATCHER; 23our $TICK_WATCHER;
25our $NEXT_TICK; 24our $NEXT_TICK;
26 25
27BEGIN { 26BEGIN {
28 @PLUGIN_EVENT = map lc, @PLUGIN_EVENT;
29
30 *CORE::GLOBAL::warn = sub { 27 *CORE::GLOBAL::warn = sub {
31 my $msg = join "", @_; 28 my $msg = join "", @_;
32 $msg .= "\n" 29 $msg .= "\n"
33 unless $msg =~ /\n$/; 30 unless $msg =~ /\n$/;
34 31
35 print STDERR "cfperl: $msg"; 32 print STDERR "cfperl: $msg";
36 LOG llevError, "cfperl: $msg"; 33 LOG llevError, "cfperl: $msg";
37 }; 34 };
38} 35}
39 36
40my %ignore_set = (MAP_PROP_PATH => 1); # I hate the plug-in api. Deeply!
41
42# generate property mutators
43sub prop_gen {
44 my ($prefix, $class) = @_;
45
46 no strict 'refs';
47
48 for my $prop (keys %PROP_TYPE) {
49 $prop =~ /^\Q$prefix\E_(.*$)/ or next;
50 my $sub = lc $1;
51
52 my $type = $PROP_TYPE{$prop};
53 my $idx = $PROP_IDX {$prop};
54
55 *{"$class\::get_$sub"} = *{"$class\::$sub"} = sub {
56 $_[0]->get_property ($type, $idx)
57 };
58
59 *{"$class\::set_$sub"} = sub {
60 $_[0]->set_property ($type, $idx, $_[1]);
61 } unless $ignore_set{$prop};
62 }
63}
64
65# auto-generate most of the API
66
67prop_gen OBJECT_PROP => "cf::object";
68# CFAPI_OBJECT_ANIMATION?
69prop_gen PLAYER_PROP => "cf::object::player";
70
71prop_gen MAP_PROP => "cf::map";
72prop_gen ARCH_PROP => "cf::arch";
73
74# guessed hierarchies
75
76@safe::cf::object::player::ISA = @cf::object::player::ISA = 'cf::object'; 37@safe::cf::object::player::ISA = @cf::object::player::ISA = 'cf::object';
77@safe::cf::object::map::ISA = @cf::object::map::ISA = 'cf::object';
78 38
79# we bless all objects into (empty) derived classes to force a method lookup 39# we bless all objects into (empty) derived classes to force a method lookup
80# within the Safe compartment. 40# within the Safe compartment.
81for my $pkg (qw(cf::object cf::object::map cf::object::player cf::player cf::map cf::party cf::region cf::arch)) { 41for my $pkg (qw(cf::object cf::object::player cf::player cf::map cf::party cf::region cf::arch cf::living)) {
82 no strict 'refs'; 42 no strict 'refs';
83 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg; 43 @{"safe::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg;
84} 44}
85 45
86$Event::DIED = sub { 46$Event::DIED = sub {
92my @hook; 52my @hook;
93my %command; 53my %command;
94my %extcmd; 54my %extcmd;
95 55
96############################################################################# 56#############################################################################
97# object support 57# utility functions
98 58
99sub reattach { 59use JSON::Syck (); # TODO# replace by JSON::PC once working
100 warn "reattach<@_>\n";
101}
102 60
103sub instantiate { 61sub from_json($) {
104 warn "instantiate<@_>\n"; 62 $JSON::Syck::ImplicitUnicode = 1; # work around JSON::Syck bugs
63 JSON::Syck::Load $_[0]
105} 64}
106 65
107sub clone { 66sub to_json($) {
108 warn "clone<@_>\n"; 67 $JSON::Syck::ImplicitUnicode = 0; # work around JSON::Syck bugs
68 JSON::Syck::Dump $_[0]
109} 69}
110 70
111############################################################################# 71#############################################################################
112# "new" plug-in system 72# "new" plug-in system
113 73
114=item cf::object::attach ... # NYI 74=head3 EVENTS AND OBJECT ATTACHMENTS
75
76=over 4
77
78=item $object->attach ($attachment, key => $value...)
79
80=item $object->detach ($attachment)
81
82Attach/detach a pre-registered attachment to an object.
83
84=item $player->attach ($attachment, key => $value...)
85
86=item $player->detach ($attachment)
87
88Attach/detach a pre-registered attachment to a player.
89
90=item $map->attach ($attachment, key => $value...)
91
92=item $map->detach ($attachment)
93
94Attach/detach a pre-registered attachment to a map.
95
96=item $bool = $object->attached ($name)
97
98=item $bool = $player->attached ($name)
99
100=item $bool = $map->attached ($name)
101
102Checks wether the named attachment is currently attached to the object.
115 103
116=item cf::attach_global ... 104=item cf::attach_global ...
117 105
118=item cf::attach_to_type ... 106Attach handlers for global events.
107
108This and all following C<attach_*>-functions expect any number of the
109following handler/hook descriptions:
110
111=over 4
112
113=item prio => $number
114
115Set the priority for all following handlers/hooks (unless overwritten
116by another C<prio> setting). Lower priority handlers get executed
117earlier. The default priority is C<0>, and many built-in handlers are
118registered at priority C<-1000>, so lower priorities should not be used
119unless you know what you are doing.
120
121=item on_I<event> => \&cb
122
123Call the given code reference whenever the named event happens (event is
124something like C<instantiate>, C<apply>, C<use_skill> and so on, and which
125handlers are recognised generally depends on the type of object these
126handlers attach to).
127
128See F<include/eventinc.h> for the full list of events supported, and their
129class.
130
131=item package => package::
132
133Look for sub functions of the name C<< on_I<event> >> in the given
134package and register them. Only handlers for eevents supported by the
135object/class are recognised.
136
137=back
138
139=item cf::attach_to_type $object_type, $subtype, ...
140
141Attach handlers for a specific object type (e.g. TRANSPORT) and
142subtype. If C<$subtype> is zero or undef, matches all objects of the given
143type.
119 144
120=item cf::attach_to_objects ... 145=item cf::attach_to_objects ...
121 146
147Attach handlers to all objects. Do not use this except for debugging or
148very rare events, as handlers are (obviously) called for I<all> objects in
149the game.
150
122=item cf::attach_to_players ... 151=item cf::attach_to_players ...
123 152
153Attach handlers to all players.
154
124=item cf::attach_to_maps ... 155=item cf::attach_to_maps ...
125 156
126 prio => $number, # lower is earlier 157Attach handlers to all maps.
127 on_xxx => \&cb, 158
128 package => package::, 159=item cf:register_attachment $name, ...
160
161Register an attachment by name through which objects can refer to this
162attachment.
163
164=item cf:register_player_attachment $name, ...
165
166Register an attachment by name through which players can refer to this
167attachment.
168
169=item cf:register_map_attachment $name, ...
170
171Register an attachment by name through which maps can refer to this
172attachment.
129 173
130=cut 174=cut
131 175
132# the following variables are defined in .xs and must not be re-created 176# the following variables are defined in .xs and must not be re-created
133our @CB_GLOBAL = (); # registry for all global events 177our @CB_GLOBAL = (); # registry for all global events
134our @CB_OBJECT = (); 178our @CB_OBJECT = (); # all objects (should not be used except in emergency)
135our @CB_PLAYER = (); 179our @CB_PLAYER = ();
136our @CB_TYPE = (); # registry for type (cf-object class) based events 180our @CB_TYPE = (); # registry for type (cf-object class) based events
137our @CB_MAP = (); 181our @CB_MAP = ();
138 182
183my %attachment;
184
139sub _attach_cb($\%$$$) { 185sub _attach_cb($\%$$$) {
140 my ($registry, $undo, $event, $prio, $cb) = @_; 186 my ($registry, $undo, $event, $prio, $cb) = @_;
141 187
142 use sort 'stable'; 188 use sort 'stable';
143 189
151} 197}
152 198
153# attach handles attaching event callbacks 199# attach handles attaching event callbacks
154# the only thing the caller has to do is pass the correct 200# the only thing the caller has to do is pass the correct
155# registry (== where the callback attaches to). 201# registry (== where the callback attaches to).
156sub _attach(\@$\@) { 202sub _attach(\@$@) {
157 my ($registry, $klass, $arg) = @_; 203 my ($registry, $klass, @arg) = @_;
158 204
159 my $prio = 0; 205 my $prio = 0;
160 206
161 my %undo = ( 207 my %undo = (
162 registry => $registry, 208 registry => $registry,
163 cb => [], 209 cb => [],
164 ); 210 );
165 211
166 my %cb_id = map +("on_" . lc $EVENT[$_][0], $_) , grep $EVENT[$_][1] == $klass, 0 .. $#EVENT; 212 my %cb_id = map +("on_" . lc $EVENT[$_][0], $_) , grep $EVENT[$_][1] == $klass, 0 .. $#EVENT;
167 213
168 while (@$arg) { 214 while (@arg) {
169 my $type = shift @$arg; 215 my $type = shift @arg;
170 216
171 if ($type eq "prio") { 217 if ($type eq "prio") {
172 $prio = shift @$arg; 218 $prio = shift @arg;
173 219
174 } elsif ($type eq "package") { 220 } elsif ($type eq "package") {
175 my $pkg = shift @$arg; 221 my $pkg = shift @arg;
176 222
177 while (my ($name, $id) = each %cb_id) { 223 while (my ($name, $id) = each %cb_id) {
178 if (my $cb = $pkg->can ($name)) { 224 if (my $cb = $pkg->can ($name)) {
179 _attach_cb $registry, %undo, $id, $prio, $cb; 225 _attach_cb $registry, %undo, $id, $prio, $cb;
180 } 226 }
181 } 227 }
182 228
183 } elsif (exists $cb_id{$type}) { 229 } elsif (exists $cb_id{$type}) {
184 _attach_cb $registry, %undo, $cb_id{$type}, $prio, shift @$arg; 230 _attach_cb $registry, %undo, $cb_id{$type}, $prio, shift @arg;
185 231
186 } elsif (ref $type) { 232 } elsif (ref $type) {
187 warn "attaching objects not supported, ignoring.\n"; 233 warn "attaching objects not supported, ignoring.\n";
188 234
189 } else { 235 } else {
190 shift @$arg; 236 shift @arg;
191 warn "attach argument '$type' not supported, ignoring.\n"; 237 warn "attach argument '$type' not supported, ignoring.\n";
192 } 238 }
193 } 239 }
194 240
195 \%undo 241 \%undo
196} 242}
197 243
244sub _attach_attachment {
245 my ($obj, $name, %arg) = @_;
246
247 return if exists $obj->{_attachment}{$name};
248
249 my $res;
250
251 if (my $attach = $attachment{$name}) {
252 my $registry = $obj->registry;
253
254 for (@$attach) {
255 my ($klass, @attach) = @$_;
256 $res = _attach @$registry, $klass, @attach;
257 }
258
259 $obj->{$name} = \%arg;
260 } else {
261 warn "object uses attachment '$name' that is not available, postponing.\n";
262 }
263
264 $obj->{_attachment}{$name} = undef;
265
266 $res->{attachment} = $name;
267 $res
268}
269
198sub cf::object::attach { 270*cf::object::attach =
199 die; 271*cf::player::attach =
200} 272*cf::map::attach = sub {
273 my ($obj, $name, %arg) = @_;
274
275 _attach_attachment $obj, $name, %arg;
276};
277
278# all those should be optimised
279*cf::object::detach =
280*cf::player::detach =
281*cf::map::detach = sub {
282 my ($obj, $name) = @_;
283
284 delete $obj->{_attachment}{$name};
285 reattach ($obj);
286};
287
288*cf::object::attached =
289*cf::player::attached =
290*cf::map::attached = sub {
291 my ($obj, $name) = @_;
292
293 exists $obj->{_attachment}{$name}
294};
201 295
202sub attach_global { 296sub attach_global {
203 _attach @CB_GLOBAL, KLASS_GLOBAL, @_ 297 _attach @CB_GLOBAL, KLASS_GLOBAL, @_
204} 298}
205 299
206sub attach_to_type { 300sub attach_to_type {
207 my $type = shift; 301 my $type = shift;
302 my $subtype = shift;
303
208 _attach @{$CB_TYPE[$type]}, KLASS_OBJECT, @_ 304 _attach @{$CB_TYPE[$type + $subtype * NUM_SUBTYPES]}, KLASS_OBJECT, @_
209} 305}
210 306
211sub attach_to_objects { 307sub attach_to_objects {
212 _attach @CB_OBJECT, KLASS_OBJECT, @_ 308 _attach @CB_OBJECT, KLASS_OBJECT, @_
213} 309}
218 314
219sub attach_to_maps { 315sub attach_to_maps {
220 _attach @CB_MAP, KLASS_MAP, @_ 316 _attach @CB_MAP, KLASS_MAP, @_
221} 317}
222 318
319sub register_attachment {
320 my $name = shift;
321
322 $attachment{$name} = [[KLASS_OBJECT, @_]];
323}
324
325sub register_player_attachment {
326 my $name = shift;
327
328 $attachment{$name} = [[KLASS_PLAYER, @_]];
329}
330
331sub register_map_attachment {
332 my $name = shift;
333
334 $attachment{$name} = [[KLASS_MAP, @_]];
335}
336
223our $override; 337our $override;
338our @invoke_results = (); # referenced from .xs code. TODO: play tricks with reify and mortals?
224 339
225sub override() { 340sub override {
226 $override = 1 341 $override = 1;
342 @invoke_results = ();
227} 343}
228 344
229sub invoke { 345sub do_invoke {
230 my $event = shift; 346 my $event = shift;
231 my $callbacks = shift; 347 my $callbacks = shift;
348
349 @invoke_results = ();
232 350
233 local $override; 351 local $override;
234 352
235 for (@$callbacks) { 353 for (@$callbacks) {
236 eval { &{$_->[1]} }; 354 eval { &{$_->[1]} };
245 } 363 }
246 364
247 0 365 0
248} 366}
249 367
368=item $bool = cf::invoke EVENT_GLOBAL_XXX, ...
369
370=item $bool = $object->invoke (EVENT_OBJECT_XXX, ...)
371
372=item $bool = $player->invoke (EVENT_PLAYER_XXX, ...)
373
374=item $bool = $map->invoke (EVENT_MAP_XXX, ...)
375
376Generate a global/object/player/map-specific event with the given arguments.
377
378This API is preliminary (most likely, the EVENT_KLASS_xxx prefix will be
379removed in future versions), and there is no public API to access override
380results (if you must, access C<@cf::invoke_results> directly).
381
382=back
383
384=head2 methods valid for all pointers
385
386=over 4
387
388=item $object->valid
389
390=item $player->valid
391
392=item $map->valid
393
394Just because you have a perl object does not mean that the corresponding
395C-level object still exists. If you try to access an object that has no
396valid C counterpart anymore you get an exception at runtime. This method
397can be used to test for existence of the C object part without causing an
398exception.
399
400=back
401
402=cut
403
404*cf::object::valid =
405*cf::player::valid =
406*cf::map::valid = \&cf::_valid;
407
408#############################################################################
409# object support
410
411sub instantiate {
412 my ($obj, $data) = @_;
413
414 $data = from_json $data;
415
416 for (@$data) {
417 my ($name, $args) = @$_;
418
419 $obj->attach ($name, %{$args || {} });
420 }
421}
422
423# basically do the same as instantiate, without calling instantiate
424sub reattach {
425 my ($obj) = @_;
426 my $registry = $obj->registry;
427
428 @$registry = ();
429
430 delete $obj->{_attachment} unless scalar keys %{ $obj->{_attachment} || {} };
431
432 for my $name (keys %{ $obj->{_attachment} || {} }) {
433 if (my $attach = $attachment{$name}) {
434 for (@$attach) {
435 my ($klass, @attach) = @$_;
436 _attach @$registry, $klass, @attach;
437 }
438 } else {
439 warn "object uses attachment '$name' that is not available, postponing.\n";
440 }
441 }
442}
443
444sub object_freezer_save {
445 my ($filename, $rdata, $objs) = @_;
446
447 if (length $$rdata) {
448 warn sprintf "saving %s (%d,%d)\n",
449 $filename, length $$rdata, scalar @$objs;
450
451 if (open my $fh, ">:raw", "$filename~") {
452 chmod SAVE_MODE, $fh;
453 syswrite $fh, $$rdata;
454 close $fh;
455
456 if (@$objs && open my $fh, ">:raw", "$filename.pst~") {
457 chmod SAVE_MODE, $fh;
458 syswrite $fh, Storable::nfreeze { version => 1, objs => $objs };
459 close $fh;
460 rename "$filename.pst~", "$filename.pst";
461 } else {
462 unlink "$filename.pst";
463 }
464
465 rename "$filename~", $filename;
466 } else {
467 warn "FATAL: $filename~: $!\n";
468 }
469 } else {
470 unlink $filename;
471 unlink "$filename.pst";
472 }
473}
474
475sub object_thawer_load {
476 my ($filename) = @_;
477
478 local $/;
479
480 my $av;
481
482 #TODO: use sysread etc.
483 if (open my $data, "<:raw:perlio", $filename) {
484 $data = <$data>;
485 if (open my $pst, "<:raw:perlio", "$filename.pst") {
486 $av = eval { (Storable::thaw <$pst>)->{objs} };
487 }
488 return ($data, $av);
489 }
490
491 ()
492}
493
494attach_to_objects
495 prio => -1000000,
496 on_clone => sub {
497 my ($src, $dst) = @_;
498
499 @{$dst->registry} = @{$src->registry};
500
501 %$dst = %$src;
502
503 %{$dst->{_attachment}} = %{$src->{_attachment}}
504 if exists $src->{_attachment};
505 },
506;
507
250############################################################################# 508#############################################################################
251# old plug-in events 509# old plug-in events
252 510
253sub inject_event { 511sub inject_event {
254 my $extension = shift; 512 my $extension = shift;
299} 557}
300 558
301sub register { 559sub register {
302 my ($base, $pkg) = @_; 560 my ($base, $pkg) = @_;
303 561
304 for my $idx (0 .. $#PLUGIN_EVENT) { 562 #TODO
305 if (my $ref = $pkg->can ("on_$PLUGIN_EVENT[$idx]")) {
306 #warn "registering $PLUGIN_EVENT[$idx] hook to '$pkg'\n";
307 $hook[$idx]{$base} = $ref;
308 }
309 }
310} 563}
311 564
312sub load_extension { 565sub load_extension {
313 my ($path) = @_; 566 my ($path) = @_;
314 567
345 my ($pkg) = @_; 598 my ($pkg) = @_;
346 599
347 warn "removing extension $pkg\n"; 600 warn "removing extension $pkg\n";
348 601
349 # remove hooks 602 # remove hooks
603 #TODO
350 for my $idx (0 .. $#PLUGIN_EVENT) { 604# for my $idx (0 .. $#PLUGIN_EVENT) {
351 delete $hook[$idx]{$pkg}; 605# delete $hook[$idx]{$pkg};
352 } 606# }
353 607
354 # remove commands 608 # remove commands
355 for my $name (keys %command) { 609 for my $name (keys %command) {
356 my @cb = grep $_->[2] ne $pkg, @{ $command{$name} }; 610 my @cb = grep $_->[2] ne $pkg, @{ $command{$name} };
357 611
423 Symbol::delete_package $k; 677 Symbol::delete_package $k;
424 } 678 }
425 679
426 # 4. get rid of safe::, as good as possible 680 # 4. get rid of safe::, as good as possible
427 Symbol::delete_package "safe::$_" 681 Symbol::delete_package "safe::$_"
428 for qw(cf::object cf::object::map cf::object::player cf::player cf::map cf::party cf::region); 682 for qw(cf::object cf::object::player cf::player cf::map cf::party cf::region);
429 683
430 # 5. remove register_script_function callbacks 684 # 5. remove register_script_function callbacks
431 # TODO 685 # TODO
432 686
433 # 6. unload cf.pm "a bit" 687 # 6. unload cf.pm "a bit"
438 #Symbol::delete_package __PACKAGE__; 692 #Symbol::delete_package __PACKAGE__;
439 693
440 # 7. reload cf.pm 694 # 7. reload cf.pm
441 $msg->("reloading cf.pm"); 695 $msg->("reloading cf.pm");
442 require cf; 696 require cf;
697
698 $msg->("load extensions");
699 cf::load_extensions;
443 }; 700 };
444 $msg->($@) if $@; 701 $msg->($@) if $@;
445 702
446 $msg->("reloaded"); 703 $msg->("reloaded");
447}; 704};
461 warn $_[0]; 718 warn $_[0];
462 $who->message ($_[0]); 719 $who->message ($_[0]);
463 }; 720 };
464 } 721 }
465}; 722};
466
467#############################################################################
468# utility functions
469
470use JSON::Syck (); # TODO# replace by JSON::PC once working
471
472sub from_json($) {
473 $JSON::Syck::ImplicitUnicode = 1; # work around JSON::Syck bugs
474 JSON::Syck::Load $_[0]
475}
476
477sub to_json($) {
478 $JSON::Syck::ImplicitUnicode = 0; # work around JSON::Syck bugs
479 JSON::Syck::Dump $_[0]
480}
481 723
482############################################################################# 724#############################################################################
483# extcmd framework, basically convert ext <msg> 725# extcmd framework, basically convert ext <msg>
484# into pkg::->on_extcmd_arg1 (...) while shortcutting a few 726# into pkg::->on_extcmd_arg1 (...) while shortcutting a few
485 727
510 my ($map) = @_; 752 my ($map) = @_;
511 753
512 my $path = $map->tmpname; 754 my $path = $map->tmpname;
513 defined $path or return; 755 defined $path or return;
514 756
515 unlink "$path.cfperl"; 757 unlink "$path.pst";
516};
517
518*cf::mapsupport::on_swapin =
519*cf::mapsupport::on_load = sub {
520 my ($map) = @_;
521
522 my $path = $map->tmpname;
523 $path = $map->path unless defined $path;
524
525 open my $fh, "<:raw", "$path.cfperl"
526 or return; # no perl data
527
528 my $data = Storable::thaw do { local $/; <$fh> };
529
530 $data->{version} <= 1
531 or return; # too new
532
533 $map->_set_obs ($data->{obs});
534};
535
536*cf::mapsupport::on_swapout = sub {
537 my ($map) = @_;
538
539 my $path = $map->tmpname;
540 $path = $map->path unless defined $path;
541
542 my $obs = $map->_get_obs;
543
544 if (defined $obs) {
545 open my $fh, ">:raw", "$path.cfperl"
546 or die "$path.cfperl: $!";
547
548 stat $path;
549
550 print $fh Storable::nfreeze {
551 size => (stat _)[7],
552 time => (stat _)[9],
553 version => 1,
554 obs => $obs,
555 };
556
557 chmod SAVE_MODE, "$path.cfperl"; # very racy, but cf-compatible *g*
558 } else {
559 unlink "$path.cfperl";
560 }
561}; 758};
562 759
563attach_to_maps prio => -10000, package => cf::mapsupport::; 760attach_to_maps prio => -10000, package => cf::mapsupport::;
564 761
565############################################################################# 762#############################################################################
567 764
568sub all_objects(@) { 765sub all_objects(@) {
569 @_, map all_objects ($_->inv), @_ 766 @_, map all_objects ($_->inv), @_
570} 767}
571 768
769# TODO: compatibility cruft, remove when no longer needed
572attach_to_players 770attach_to_players
573 on_load => sub { 771 on_load => sub {
574 my ($pl, $path) = @_; 772 my ($pl, $path) = @_;
575 773
576 for my $o (all_objects $pl->ob) { 774 for my $o (all_objects $pl->ob) {
578 $o->set_ob_key_value ("_perl_data"); 776 $o->set_ob_key_value ("_perl_data");
579 777
580 %$o = %{ Storable::thaw pack "H*", $value }; 778 %$o = %{ Storable::thaw pack "H*", $value };
581 } 779 }
582 } 780 }
583 },
584 on_save => sub {
585 my ($pl, $path) = @_;
586
587 $_->set_ob_key_value (_perl_data => unpack "H*", Storable::nfreeze $_)
588 for grep %$_, all_objects $pl->ob;
589 }, 781 },
590; 782;
591 783
592############################################################################# 784#############################################################################
593# core extensions - in perl 785# core extensions - in perl
703 895
704############################################################################# 896#############################################################################
705# the server's main() 897# the server's main()
706 898
707sub main { 899sub main {
900 load_extensions;
708 Event::loop; 901 Event::loop;
709} 902}
710 903
711############################################################################# 904#############################################################################
712# initialisation 905# initialisation
713 906
714register "<global>", __PACKAGE__; 907register "<global>", __PACKAGE__;
715 908
716unshift @INC, $LIBDIR; 909unshift @INC, $LIBDIR;
717
718load_extensions;
719 910
720$TICK_WATCHER = Event->timer ( 911$TICK_WATCHER = Event->timer (
721 prio => 1, 912 prio => 1,
722 at => $NEXT_TICK || 1, 913 at => $NEXT_TICK || 1,
723 cb => sub { 914 cb => sub {
732 $TICK_WATCHER->at ($NEXT_TICK); 923 $TICK_WATCHER->at ($NEXT_TICK);
733 $TICK_WATCHER->start; 924 $TICK_WATCHER->start;
734 }, 925 },
735); 926);
736 927
928_reload_2;
929
7371 9301
738 931

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines