summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorDaniel Bovensiepen <[email protected]>2012-05-16 11:34:00 -0700
committerDaniel Bovensiepen <[email protected]>2012-05-16 11:34:00 -0700
commit0cc8dcc0ee658eca9193a5611104f6d05cb958fd (patch)
tree0c123371d208a692f80197c1b0babb631302442a /src
parent3bec8b330c58a7ac9a73ed3689b1bd9cde389c16 (diff)
parent25415302399055a566e4d55b6c165937943aa678 (diff)
downloadmruby-0cc8dcc0ee658eca9193a5611104f6d05cb958fd.tar.gz
mruby-0cc8dcc0ee658eca9193a5611104f6d05cb958fd.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'src')
-rw-r--r--src/class.c13
-rw-r--r--src/math.c48
-rw-r--r--src/time.c4
3 files changed, 39 insertions, 26 deletions
diff --git a/src/class.c b/src/class.c
index 7cb25f5c4..9bb924df0 100644
--- a/src/class.c
+++ b/src/class.c
@@ -578,6 +578,19 @@ mrb_define_class_method(mrb_state *mrb, struct RClass *c, const char *name, mrb_
mrb_define_method_id(mrb, c->c, mrb_intern(mrb, name), func, aspec);
}
+void
+mrb_define_singleton_method(mrb_state *mrb, struct RObject *o, const char *name, mrb_func_t func, int aspec)
+{
+ mrb_define_method_id(mrb, mrb_singleton_class_ptr(mrb, o->c), mrb_intern(mrb, name), func, aspec);
+}
+
+void
+mrb_define_module_function(mrb_state *mrb, struct RClass *c, const char *name, mrb_func_t func, int aspec)
+{
+ mrb_define_class_method(mrb, c, name, func, aspec);
+ mrb_define_method(mrb, c, name, func, aspec);
+}
+
struct RProc*
mrb_method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid)
{
diff --git a/src/math.c b/src/math.c
index cbe773c58..73bcf5e2a 100644
--- a/src/math.c
+++ b/src/math.c
@@ -622,34 +622,34 @@ mrb_init_math(mrb_state *mrb)
mrb_define_const(mrb, mrb_math, "E", mrb_float_value(exp(1.0)));
#endif
- mrb_define_class_method(mrb, mrb_math, "sin", math_sin, 1);
- mrb_define_class_method(mrb, mrb_math, "cos", math_cos, 1);
- mrb_define_class_method(mrb, mrb_math, "tan", math_tan, 1);
-
- mrb_define_class_method(mrb, mrb_math, "asin", math_asin, 1);
- mrb_define_class_method(mrb, mrb_math, "acos", math_acos, 1);
- mrb_define_class_method(mrb, mrb_math, "atan", math_atan, 1);
- mrb_define_class_method(mrb, mrb_math, "atan2", math_atan2, 2);
+ mrb_define_module_function(mrb, mrb_math, "sin", math_sin, 1);
+ mrb_define_module_function(mrb, mrb_math, "cos", math_cos, 1);
+ mrb_define_module_function(mrb, mrb_math, "tan", math_tan, 1);
+
+ mrb_define_module_function(mrb, mrb_math, "asin", math_asin, 1);
+ mrb_define_module_function(mrb, mrb_math, "acos", math_acos, 1);
+ mrb_define_module_function(mrb, mrb_math, "atan", math_atan, 1);
+ mrb_define_module_function(mrb, mrb_math, "atan2", math_atan2, 2);
- mrb_define_class_method(mrb, mrb_math, "sinh", math_sinh, 1);
- mrb_define_class_method(mrb, mrb_math, "cosh", math_cosh, 1);
- mrb_define_class_method(mrb, mrb_math, "tanh", math_tanh, 1);
+ mrb_define_module_function(mrb, mrb_math, "sinh", math_sinh, 1);
+ mrb_define_module_function(mrb, mrb_math, "cosh", math_cosh, 1);
+ mrb_define_module_function(mrb, mrb_math, "tanh", math_tanh, 1);
- mrb_define_class_method(mrb, mrb_math, "asinh", math_asinh, 1);
- mrb_define_class_method(mrb, mrb_math, "acosh", math_acosh, 1);
- mrb_define_class_method(mrb, mrb_math, "atanh", math_atanh, 1);
+ mrb_define_module_function(mrb, mrb_math, "asinh", math_asinh, 1);
+ mrb_define_module_function(mrb, mrb_math, "acosh", math_acosh, 1);
+ mrb_define_module_function(mrb, mrb_math, "atanh", math_atanh, 1);
- mrb_define_class_method(mrb, mrb_math, "exp", math_exp, 1);
- mrb_define_class_method(mrb, mrb_math, "log", math_log, -1);
- mrb_define_class_method(mrb, mrb_math, "log2", math_log2, 1);
- mrb_define_class_method(mrb, mrb_math, "log10", math_log10, 1);
- mrb_define_class_method(mrb, mrb_math, "cbrt", math_cbrt, 1);
+ mrb_define_module_function(mrb, mrb_math, "exp", math_exp, 1);
+ mrb_define_module_function(mrb, mrb_math, "log", math_log, -1);
+ mrb_define_module_function(mrb, mrb_math, "log2", math_log2, 1);
+ mrb_define_module_function(mrb, mrb_math, "log10", math_log10, 1);
+ mrb_define_module_function(mrb, mrb_math, "cbrt", math_cbrt, 1);
- mrb_define_class_method(mrb, mrb_math, "frexp", math_frexp, 1);
- mrb_define_class_method(mrb, mrb_math, "ldexp", math_ldexp, 2);
+ mrb_define_module_function(mrb, mrb_math, "frexp", math_frexp, 1);
+ mrb_define_module_function(mrb, mrb_math, "ldexp", math_ldexp, 2);
- mrb_define_class_method(mrb, mrb_math, "hypot", math_hypot, 2);
+ mrb_define_module_function(mrb, mrb_math, "hypot", math_hypot, 2);
- mrb_define_class_method(mrb, mrb_math, "erf", math_erf, 1);
- mrb_define_class_method(mrb, mrb_math, "erfc", math_erfc, 1);
+ mrb_define_module_function(mrb, mrb_math, "erf", math_erf, 1);
+ mrb_define_module_function(mrb, mrb_math, "erfc", math_erfc, 1);
}
diff --git a/src/time.c b/src/time.c
index 5e75152e6..b0a74d0d1 100644
--- a/src/time.c
+++ b/src/time.c
@@ -28,8 +28,8 @@
#ifdef _WIN32
/* Win32 platform do not provide gmtime_r/localtime_r; emulate them using gmtime_s/localtime_s */
#if _MVC_VER
-#define gmtime_r(tp, tm) ((gmtime_s((tm), (tp)) == 0) ? (tp) : NULL)
-#define localtime_r(tp, tm) ((localtime_s((tm), (tp)) == 0) ? (tp) : NULL)
+#define gmtime_r(tp, tm) ((gmtime_s((tm), (tp)) == 0) ? (tm) : NULL)
+#define localtime_r(tp, tm) ((localtime_s((tm), (tp)) == 0) ? (tm) : NULL)
#else
#define NO_GMTIME_R
#endif