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.24 by root, Wed Jul 19 22:51:40 2006 UTC vs.
Revision 1.25 by root, Thu Jul 20 07:22:40 2006 UTC

64prop_gen MAP_PROP => "cf::map"; 64prop_gen MAP_PROP => "cf::map";
65prop_gen ARCH_PROP => "cf::arch"; 65prop_gen ARCH_PROP => "cf::arch";
66 66
67# guessed hierarchies 67# guessed hierarchies
68 68
69@cf::object::player::ISA = 'cf::object'; 69@ext::cf::object::player::ISA = @cf::object::player::ISA = 'cf::object';
70@cf::object::map::ISA = 'cf::object'; 70@ext::cf::object::map::ISA = @cf::object::map::ISA = 'cf::object';
71
72# we bless all objects into derived classes to force a method lookup
73# within the Safe compartment.
74for my $pkg (qw(cf::object cf::object::map cf::object::player cf::player cf::map cf::party cf::region)) {
75 no strict 'refs';
76 @{"ext::$pkg\::wrap::ISA"} = @{"$pkg\::wrap::ISA"} = $pkg;
77}
71 78
72$Event::DIED = sub { 79$Event::DIED = sub {
73 warn "error in event callback: @_"; 80 warn "error in event callback: @_";
74}; 81};
75 82
389 396
390$SIG{FPE} = 'IGNORE'; 397$SIG{FPE} = 'IGNORE';
391 398
392$safe->permit_only (Opcode::opset qw(:base_core :base_mem :base_orig :base_math sort time)); 399$safe->permit_only (Opcode::opset qw(:base_core :base_mem :base_orig :base_math sort time));
393 400
394# here we would export the classes and methods available to script code 401# here we export the classes and methods available to script code
395#@ext::cf::object::player::ISA = @cf::object::player::ISA; 402
396#@ext::cf::object::map::ISA = @cf::object::map::ISA; 403for (
404 ["cf::object" => qw(contr)],
405 ["cf::object::player" => qw(player)],
406 ["cf::player" => qw(peaceful)],
407) {
408 no strict 'refs';
409 my ($pkg, @funs) = @$_;
410 *{"ext::$pkg\::$_"} = $safe_hole->wrap (\&{"$pkg\::$_"})
411 for @funs;
412}
397 413
398sub safe_eval($;@) { 414sub safe_eval($;@) {
399 my ($code, %vars) = @_; 415 my ($code, %vars) = @_;
400 416
401 my $qcode = $code; 417 my $qcode = $code;
403 $qcode =~ s/\n/\\n/g; 419 $qcode =~ s/\n/\\n/g;
404 420
405 local $_; 421 local $_;
406 local @ext::cf::_safe_eval_args = values %vars; 422 local @ext::cf::_safe_eval_args = values %vars;
407 423
408 $safe->reval ( 424 $code =
409 "do {\n" 425 "do {\n"
410 . "my (" . (join ",", map "\$$_", keys %vars) . ") = \@cf::_safe_eval_args;\n" 426 . "my (" . (join ",", map "\$$_", keys %vars) . ") = \@cf::_safe_eval_args;\n"
411 . "#line 0 \"{$qcode}\"\n" 427 . "#line 0 \"{$qcode}\"\n"
412 . $code 428 . $code
413 . "\n}" 429 . "\n}"
414 ) 430 ;
431
432 sub_generation_inc;
433 my @res = wantarray ? $safe->reval ($code) : scalar $safe->reval ($code);
434 sub_generation_inc;
435
436 wantarray ? @res : $res[0]
415} 437}
416 438
417sub register_script_function { 439sub register_script_function {
418 my ($fun, $cb) = @_; 440 my ($fun, $cb) = @_;
419 441

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines