source: EcnlProtoTool/trunk/mruby-1.2.0/mrbgems/mruby-hash-ext/src/hash-ext.c@ 270

Last change on this file since 270 was 270, checked in by coas-nagasima, 7 years ago

mruby版ECNLプロトタイピング・ツールを追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 1.0 KB
Line 
1/*
2** hash.c - Hash class
3**
4** See Copyright Notice in mruby.h
5*/
6
7#include "mruby.h"
8#include "mruby/array.h"
9#include "mruby/hash.h"
10
11/*
12 * call-seq:
13 * hsh.values_at(key, ...) -> array
14 *
15 * Return an array containing the values associated with the given keys.
16 * Also see <code>Hash.select</code>.
17 *
18 * h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" }
19 * h.values_at("cow", "cat") #=> ["bovine", "feline"]
20 */
21
22static mrb_value
23hash_values_at(mrb_state *mrb, mrb_value hash)
24{
25 mrb_value *argv, result;
26 mrb_int argc, i;
27 int ai;
28
29 mrb_get_args(mrb, "*", &argv, &argc);
30 result = mrb_ary_new_capa(mrb, argc);
31 ai = mrb_gc_arena_save(mrb);
32 for (i = 0; i < argc; i++) {
33 mrb_ary_push(mrb, result, mrb_hash_get(mrb, hash, argv[i]));
34 mrb_gc_arena_restore(mrb, ai);
35 }
36 return result;
37}
38
39void
40mrb_mruby_hash_ext_gem_init(mrb_state *mrb)
41{
42 struct RClass *h;
43
44 h = mrb->hash_class;
45 mrb_define_method(mrb, h, "values_at", hash_values_at, MRB_ARGS_ANY());
46}
47
48void
49mrb_mruby_hash_ext_gem_final(mrb_state *mrb)
50{
51}
Note: See TracBrowser for help on using the repository browser.