summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-struct
diff options
context:
space:
mode:
Diffstat (limited to 'mrbgems/mruby-struct')
-rw-r--r--mrbgems/mruby-struct/src/struct.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c
index 3a0369ecb..9d749a152 100644
--- a/mrbgems/mruby-struct/src/struct.c
+++ b/mrbgems/mruby-struct/src/struct.c
@@ -4,6 +4,7 @@
** See Copyright Notice in mruby.h
*/
+#include <ctype.h>
#include <string.h>
#include "mruby.h"
#include "mruby/array.h"
@@ -209,19 +210,18 @@ mrb_struct_set_m(mrb_state *mrb, mrb_value obj)
return mrb_struct_set(mrb, obj, val);
}
-#define is_notop_id(id) (id) /* ((id)>tLAST_TOKEN) */
-#define is_local_id(id) (is_notop_id(id)) /* &&((id)&ID_SCOPE_MASK)==ID_LOCAL) */
static mrb_bool
-mrb_is_local_id(mrb_sym id)
+mrb_is_local_id(mrb_state *mrb, mrb_sym id)
{
- return !!is_local_id(id);
+ const char *name = mrb_sym2name_len(mrb, id, NULL);
+ return !ISUPPER(name[0]);
}
-#define is_const_id(id) (is_notop_id(id)) /* &&((id)&ID_SCOPE_MASK)==ID_CONST) */
static mrb_bool
-mrb_is_const_id(mrb_sym id)
+mrb_is_const_id(mrb_state *mrb, mrb_sym id)
{
- return !!is_const_id(id);
+ const char *name = mrb_sym2name_len(mrb, id, NULL);
+ return ISUPPER(name[0]);
}
static mrb_value
@@ -240,7 +240,7 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass * k
/* old style: should we warn? */
name = mrb_str_to_str(mrb, name);
id = mrb_obj_to_sym(mrb, name);
- if (!mrb_is_const_id(id)) {
+ if (!mrb_is_const_id(mrb, id)) {
mrb_name_error(mrb, id, "identifier %S needs to be constant", name);
}
if (mrb_const_defined_at(mrb, klass, id)) {
@@ -262,7 +262,7 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass * k
ai = mrb_gc_arena_save(mrb);
for (i=0; i< len; i++) {
mrb_sym id = mrb_symbol(ptr_members[i]);
- if (mrb_is_local_id(id) || mrb_is_const_id(id)) {
+ if (mrb_is_local_id(mrb, id) || mrb_is_const_id(mrb, id)) {
if (i < N_REF_FUNC) {
mrb_define_method_id(mrb, c, id, ref_func[i], MRB_ARGS_NONE());
}
@@ -438,7 +438,7 @@ inspect_struct(mrb_state *mrb, mrb_value s, mrb_bool recur)
}
slot = ptr_members[i];
id = mrb_symbol(slot);
- if (mrb_is_local_id(id) || mrb_is_const_id(id)) {
+ if (mrb_is_local_id(mrb, id) || mrb_is_const_id(mrb, id)) {
const char *name;
mrb_int len;