Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
9b0ef58a
Commit
9b0ef58a
authored
Sep 06, 2018
by
dearblue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A class/module name is now defined for meta programing
parent
2a24b40d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
+33
-0
src/variable.c
src/variable.c
+33
-0
No files found.
src/variable.c
View file @
9b0ef58a
...
@@ -344,6 +344,8 @@ mrb_iv_get(mrb_state *mrb, mrb_value obj, mrb_sym sym)
...
@@ -344,6 +344,8 @@ mrb_iv_get(mrb_state *mrb, mrb_value obj, mrb_sym sym)
return
mrb_nil_value
();
return
mrb_nil_value
();
}
}
static
inline
void
assign_class_name
(
mrb_state
*
mrb
,
struct
RObject
*
obj
,
mrb_sym
sym
,
mrb_value
v
);
MRB_API
void
MRB_API
void
mrb_obj_iv_set
(
mrb_state
*
mrb
,
struct
RObject
*
obj
,
mrb_sym
sym
,
mrb_value
v
)
mrb_obj_iv_set
(
mrb_state
*
mrb
,
struct
RObject
*
obj
,
mrb_sym
sym
,
mrb_value
v
)
{
{
...
@@ -352,6 +354,7 @@ mrb_obj_iv_set(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v)
...
@@ -352,6 +354,7 @@ mrb_obj_iv_set(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v)
if
(
MRB_FROZEN_P
(
obj
))
{
if
(
MRB_FROZEN_P
(
obj
))
{
mrb_raisef
(
mrb
,
E_FROZEN_ERROR
,
"can't modify frozen %S"
,
mrb_obj_value
(
obj
));
mrb_raisef
(
mrb
,
E_FROZEN_ERROR
,
"can't modify frozen %S"
,
mrb_obj_value
(
obj
));
}
}
assign_class_name
(
mrb
,
obj
,
sym
,
v
);
if
(
!
obj
->
iv
)
{
if
(
!
obj
->
iv
)
{
obj
->
iv
=
iv_new
(
mrb
);
obj
->
iv
=
iv_new
(
mrb
);
}
}
...
@@ -360,6 +363,36 @@ mrb_obj_iv_set(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v)
...
@@ -360,6 +363,36 @@ mrb_obj_iv_set(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v)
mrb_write_barrier
(
mrb
,
(
struct
RBasic
*
)
obj
);
mrb_write_barrier
(
mrb
,
(
struct
RBasic
*
)
obj
);
}
}
static
inline
mrb_bool
is_namespace
(
enum
mrb_vtype
tt
)
{
return
tt
==
MRB_TT_CLASS
||
tt
==
MRB_TT_MODULE
?
TRUE
:
FALSE
;
}
static
inline
void
assign_class_name
(
mrb_state
*
mrb
,
struct
RObject
*
obj
,
mrb_sym
sym
,
mrb_value
v
)
{
if
(
is_namespace
(
obj
->
tt
)
&&
is_namespace
(
mrb_type
(
v
))
&&
ISUPPER
(
mrb_sym2name
(
mrb
,
sym
)[
0
]))
{
struct
RObject
*
c
=
mrb_obj_ptr
(
v
);
mrb_sym
id_classname
=
mrb_intern_lit
(
mrb
,
"__classname__"
);
mrb_value
o
=
mrb_obj_iv_get
(
mrb
,
c
,
id_classname
);
if
(
mrb_nil_p
(
o
))
{
mrb_sym
id_outer
=
mrb_intern_lit
(
mrb
,
"__outer__"
);
o
=
mrb_obj_iv_get
(
mrb
,
c
,
id_outer
);
if
(
mrb_nil_p
(
o
))
{
if
((
struct
RClass
*
)
obj
==
mrb
->
object_class
)
{
mrb_obj_iv_set
(
mrb
,
c
,
id_classname
,
mrb_symbol_value
(
sym
));
}
else
{
mrb_obj_iv_set
(
mrb
,
c
,
id_outer
,
mrb_obj_value
(
obj
));
}
}
}
}
}
MRB_API
void
MRB_API
void
mrb_iv_set
(
mrb_state
*
mrb
,
mrb_value
obj
,
mrb_sym
sym
,
mrb_value
v
)
mrb_iv_set
(
mrb_state
*
mrb
,
mrb_value
obj
,
mrb_sym
sym
,
mrb_value
v
)
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment