Files
mruby-mruby/src/enum.c
T
Yukihiro "Matz" Matsumoto 8956c5abb5 mruby.h: include mruby/presym.h for all source files
Since presym is now mandatory, mruby.h includes presym.h so that
MRB_SYM() macros are available everywhere without explicit include.
Remove redundant #include <mruby/presym.h> from all source files.

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-09 16:50:58 +09:00

30 lines
674 B
C

/*
** enum.c - Enumerable module
**
** See Copyright Notice in mruby.h
*/
#include <mruby.h>
#include <mruby/proc.h>
/* internal method `__update_hash(oldhash, index, itemhash)` */
static mrb_value
enum_update_hash(mrb_state *mrb, mrb_value self)
{
mrb_int hash;
mrb_int index;
mrb_int hv;
mrb_get_args(mrb, "iii", &hash, &index, &hv);
hash ^= ((uint32_t)hv << (index % 16));
return mrb_int_value(mrb, hash);
}
void
mrb_init_enumerable(mrb_state *mrb)
{
struct RClass *enumerable = mrb_define_module_id(mrb, MRB_SYM(Enumerable)); /* 15.3.2 */
mrb_define_module_function_id(mrb, enumerable, MRB_SYM(__update_hash), enum_update_hash, MRB_ARGS_REQ(3));
}