Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
e9137b94
Commit
e9137b94
authored
11 years ago
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
py: Implement getattr() builtin.
parent
9b196cdd
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
py/builtin.c
+7
-0
7 additions, 0 deletions
py/builtin.c
py/builtin.h
+1
-0
1 addition, 0 deletions
py/builtin.h
py/builtintables.c
+1
-0
1 addition, 0 deletions
py/builtintables.c
py/qstrdefs.h
+1
-0
1 addition, 0 deletions
py/qstrdefs.h
tests/basics/getattr1.py
+15
-0
15 additions, 0 deletions
tests/basics/getattr1.py
with
25 additions
and
0 deletions
py/builtin.c
+
7
−
0
View file @
e9137b94
...
...
@@ -381,3 +381,10 @@ STATIC mp_obj_t mp_builtin_id(mp_obj_t o_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1
(
mp_builtin_id_obj
,
mp_builtin_id
);
STATIC
mp_obj_t
mp_builtin_getattr
(
mp_obj_t
o_in
,
mp_obj_t
attr
)
{
assert
(
MP_OBJ_IS_QSTR
(
attr
));
return
rt_load_attr
(
o_in
,
MP_OBJ_QSTR_VALUE
(
attr
));
}
MP_DEFINE_CONST_FUN_OBJ_2
(
mp_builtin_getattr_obj
,
mp_builtin_getattr
);
This diff is collapsed.
Click to expand it.
py/builtin.h
+
1
−
0
View file @
e9137b94
...
...
@@ -12,6 +12,7 @@ MP_DECLARE_CONST_FUN_OBJ(mp_builtin_dir_obj);
MP_DECLARE_CONST_FUN_OBJ
(
mp_builtin_divmod_obj
);
MP_DECLARE_CONST_FUN_OBJ
(
mp_builtin_eval_obj
);
MP_DECLARE_CONST_FUN_OBJ
(
mp_builtin_exec_obj
);
MP_DECLARE_CONST_FUN_OBJ
(
mp_builtin_getattr_obj
);
MP_DECLARE_CONST_FUN_OBJ
(
mp_builtin_hash_obj
);
MP_DECLARE_CONST_FUN_OBJ
(
mp_builtin_id_obj
);
MP_DECLARE_CONST_FUN_OBJ
(
mp_builtin_isinstance_obj
);
...
...
This diff is collapsed.
Click to expand it.
py/builtintables.c
+
1
−
0
View file @
e9137b94
...
...
@@ -60,6 +60,7 @@ STATIC const mp_builtin_elem_t builtin_object_table[] = {
{
MP_QSTR_divmod
,
(
mp_obj_t
)
&
mp_builtin_divmod_obj
},
{
MP_QSTR_eval
,
(
mp_obj_t
)
&
mp_builtin_eval_obj
},
{
MP_QSTR_exec
,
(
mp_obj_t
)
&
mp_builtin_exec_obj
},
{
MP_QSTR_getattr
,
(
mp_obj_t
)
&
mp_builtin_getattr_obj
},
{
MP_QSTR_hash
,
(
mp_obj_t
)
&
mp_builtin_hash_obj
},
{
MP_QSTR_id
,
(
mp_obj_t
)
&
mp_builtin_id_obj
},
{
MP_QSTR_isinstance
,
(
mp_obj_t
)
&
mp_builtin_isinstance_obj
},
...
...
This diff is collapsed.
Click to expand it.
py/qstrdefs.h
+
1
−
0
View file @
e9137b94
...
...
@@ -92,6 +92,7 @@ Q(eval)
Q
(
exec
)
Q
(
filter
)
Q
(
float
)
Q
(
getattr
)
Q
(
hash
)
Q
(
id
)
Q
(
int
)
...
...
This diff is collapsed.
Click to expand it.
tests/basics/getattr1.py
0 → 100644
+
15
−
0
View file @
e9137b94
class
A
:
var
=
132
def
__init__
(
self
):
self
.
var2
=
34
def
meth
(
self
,
i
):
return
42
+
i
a
=
A
()
print
(
getattr
(
a
,
"
var
"
))
print
(
getattr
(
a
,
"
var2
"
))
print
(
getattr
(
a
,
"
meth
"
)(
5
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment