Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initialize sprintf argument handler when needed.
  • Loading branch information
colomon committed Jul 19, 2013
1 parent 624ff76 commit ba6da77
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/core/Cool.pm
@@ -1,6 +1,14 @@
my role IO { ... }
my class IO::Handle { ... }

my class SprintfHandler {
method mine($x) { nqp::reprname($x) eq "P6opaque"; }

method int($x) { $x.Int }
}

my $sprintfHandlerInitialized = False;

my class Cool {

## numeric methods
Expand Down Expand Up @@ -65,6 +73,12 @@ my class Cool {
}

method fmt($format = '%s') {
#?if jvm
unless $sprintfHandlerInitialized {
nqp::sprintfAddHandler(SprintfHandler.new);
$sprintfHandlerInitialized = True;
}
#?endif
nqp::p6box_s(
nqp::sprintf(nqp::unbox_s($format.Stringy), nqp::list(self))
)
Expand Down Expand Up @@ -238,6 +252,13 @@ proto sub tclc($) is pure { * }
multi sub tclc(Cool $x) { tclc $x.Str }

sub sprintf(Cool $format, *@args) {
#?if jvm
unless $sprintfHandlerInitialized {
nqp::sprintfAddHandler(SprintfHandler.new);
$sprintfHandlerInitialized = True;
}
#?endif

@args.gimme(*);
nqp::p6box_s(
nqp::sprintf(nqp::unbox_s($format.Stringy),
Expand Down

0 comments on commit ba6da77

Please sign in to comment.