diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-03-04 06:46:31 -0800 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2013-03-04 06:46:31 -0800 |
| commit | 0fd14e53a217ff8618e102080754dd8dbd9f271d (patch) | |
| tree | f55743427918df1e4f6177ac7ba236c3cd6ab42c | |
| parent | c3d5c4edea8454affc027d181798a63946f348d4 (diff) | |
| parent | 97136825e2ccfdf71cfd0cc1b1e7e8ff4f113c8c (diff) | |
| download | mruby-0fd14e53a217ff8618e102080754dd8dbd9f271d.tar.gz mruby-0fd14e53a217ff8618e102080754dd8dbd9f271d.zip | |
Merge pull request #943 from monaka/pr-tmp-move-sprintf-to-mrbgem
Move Kernel#sprintf to mrbgem
| -rw-r--r-- | build_config.rb | 3 | ||||
| -rw-r--r-- | include/mrbconf.h | 4 | ||||
| -rw-r--r-- | mrbgems/mruby-sprintf/mrbgem.rake | 4 | ||||
| -rw-r--r-- | mrbgems/mruby-sprintf/src/kernel.c | 30 | ||||
| -rw-r--r-- | mrbgems/mruby-sprintf/src/sprintf.c (renamed from src/sprintf.c) | 4 | ||||
| -rw-r--r-- | mrbgems/mruby-sprintf/test/sprintf.rb | 3 | ||||
| -rw-r--r-- | src/kernel.c | 5 |
7 files changed, 40 insertions, 13 deletions
diff --git a/build_config.rb b/build_config.rb index d3feccd71..3c089d8cc 100644 --- a/build_config.rb +++ b/build_config.rb @@ -20,6 +20,9 @@ MRuby::Build.new do |conf| # Use standard Struct class conf.gem 'mrbgems/mruby-struct' + # Use standard Kernel#sprintf method + conf.gem 'mrbgems/mruby-sprintf' + # Generate binaries # conf.bins = %w(mrbc mruby mirb) diff --git a/include/mrbconf.h b/include/mrbconf.h index 613f0575e..8a46e48ba 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -47,7 +47,6 @@ //#define POOL_PAGE_SIZE 16000 /* -DDISABLE_XXXX to drop following features */ -//#define DISABLE_SPRINTF /* Kernel.sprintf method */ //#define DISABLE_STDIO /* use of stdio */ /* -DENABLE_XXXX to enable following features */ @@ -83,9 +82,6 @@ typedef short mrb_sym; /* define ENABLE_XXXX from DISABLE_XXX */ -#ifndef DISABLE_SPRINTF -#define ENABLE_SPRINTF -#endif #ifndef DISABLE_STDIO #define ENABLE_STDIO #endif diff --git a/mrbgems/mruby-sprintf/mrbgem.rake b/mrbgems/mruby-sprintf/mrbgem.rake new file mode 100644 index 000000000..8772a5174 --- /dev/null +++ b/mrbgems/mruby-sprintf/mrbgem.rake @@ -0,0 +1,4 @@ +MRuby::Gem::Specification.new('mruby-sprintf') do |spec| + spec.license = 'MIT' + spec.authors = 'mruby developers' +end diff --git a/mrbgems/mruby-sprintf/src/kernel.c b/mrbgems/mruby-sprintf/src/kernel.c new file mode 100644 index 000000000..8f54a3d85 --- /dev/null +++ b/mrbgems/mruby-sprintf/src/kernel.c @@ -0,0 +1,30 @@ +/* +** kernel.c - Kernel module suppliment +** +** See Copyright Notice in mruby.h +*/ + +#include "mruby.h" + +mrb_value mrb_f_sprintf(mrb_state *mrb, mrb_value obj); /* in sprintf.c */ + +void +mrb_mruby_sprintf_gem_init(mrb_state* mrb) +{ + struct RClass *krn; + + if (mrb->kernel_module == NULL) { + mrb->kernel_module = mrb_define_module(mrb, "Kernel"); /* Might be PARANOID. */ + } + krn = mrb->kernel_module; + + mrb_define_method(mrb, krn, "sprintf", mrb_f_sprintf, ARGS_ANY()); + mrb_define_method(mrb, krn, "format", mrb_f_sprintf, ARGS_ANY()); +} + +void +mrb_mruby_sprintf_gem_final(mrb_state* mrb) +{ + /* nothing to do. */ +} + diff --git a/src/sprintf.c b/mrbgems/mruby-sprintf/src/sprintf.c index 192d44735..12ed05d13 100644 --- a/src/sprintf.c +++ b/mrbgems/mruby-sprintf/src/sprintf.c @@ -6,8 +6,6 @@ #include "mruby.h" -#ifdef ENABLE_SPRINTF - #include <stdio.h> #include <string.h> #include "mruby/string.h" @@ -1091,5 +1089,3 @@ fmt_setup(char *buf, size_t size, int c, int flags, int width, int prec) *buf++ = c; *buf = '\0'; } - -#endif /* ENABLE_SPRINTF */ diff --git a/mrbgems/mruby-sprintf/test/sprintf.rb b/mrbgems/mruby-sprintf/test/sprintf.rb new file mode 100644 index 000000000..52e94fb83 --- /dev/null +++ b/mrbgems/mruby-sprintf/test/sprintf.rb @@ -0,0 +1,3 @@ +## +# Kernel#sprintf Kernel#format Test + diff --git a/src/kernel.c b/src/kernel.c index c37b627a1..7187a125d 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1108,11 +1108,6 @@ mrb_init_kernel(mrb_state *mrb) mrb_define_method(mrb, krn, "singleton_methods", mrb_obj_singleton_methods_m, ARGS_ANY()); /* 15.3.1.3.45 */ mrb_define_method(mrb, krn, "to_s", mrb_any_to_s, ARGS_NONE()); /* 15.3.1.3.46 */ -#ifdef ENABLE_SPRINTF - mrb_define_method(mrb, krn, "sprintf", mrb_f_sprintf, ARGS_ANY()); /* in sprintf.c */ - mrb_define_method(mrb, krn, "format", mrb_f_sprintf, ARGS_ANY()); /* in sprintf.c */ -#endif - mrb_include_module(mrb, mrb->object_class, mrb->kernel_module); mrb_alias_method(mrb, mrb->module_class, mrb_intern(mrb, "dup"), mrb_intern(mrb, "clone")); } |
