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
6954153f
Commit
6954153f
authored
Mar 23, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1057 from mattn/mruby-print
mruby-print gem
parents
f0ac204f
b69761e2
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
126 additions
and
100 deletions
+126
-100
build_config.rb
build_config.rb
+3
-0
mrbgems/mruby-print/mrbgem.rake
mrbgems/mruby-print/mrbgem.rake
+4
-0
mrbgems/mruby-print/mrblib/print.rb
mrbgems/mruby-print/mrblib/print.rb
+64
-0
mrbgems/mruby-print/src/print.c
mrbgems/mruby-print/src/print.c
+44
-0
mrblib/print.rb
mrblib/print.rb
+11
-73
src/init.c
src/init.c
+0
-4
src/print.c
src/print.c
+0
-23
No files found.
build_config.rb
View file @
6954153f
...
...
@@ -11,6 +11,9 @@ MRuby::Build.new do |conf|
# conf.gem :github => 'masuidrive/mrbgems-example', :branch => 'master'
# conf.gem :git => 'git@github.com:masuidrive/mrbgems-example.git', :branch => 'master', :options => '-v'
# Use standard print/puts/p
conf
.
gem
"
#{
root
}
/mrbgems/mruby-print"
# Use standard Math module
conf
.
gem
"
#{
root
}
/mrbgems/mruby-math"
...
...
mrbgems/mruby-print/mrbgem.rake
0 → 100644
View file @
6954153f
MRuby
::
Gem
::
Specification
.
new
(
'mruby-print'
)
do
|
spec
|
spec
.
license
=
'MIT'
spec
.
authors
=
'mruby developers'
end
mrbgems/mruby-print/mrblib/print.rb
0 → 100644
View file @
6954153f
##
# Kernel
#
# ISO 15.3.1
module
Kernel
##
# Invoke method +print+ on STDOUT and passing +*args+
#
# ISO 15.3.1.2.10
def
print
(
*
args
)
i
=
0
len
=
args
.
size
while
i
<
len
__printstr__
args
[
i
].
to_s
i
+=
1
end
end
##
# Invoke method +puts+ on STDOUT and passing +*args*+
#
# ISO 15.3.1.2.11
def
puts
(
*
args
)
i
=
0
len
=
args
.
size
while
i
<
len
s
=
args
[
i
].
to_s
__printstr__
s
__printstr__
"
\n
"
if
(
s
[
-
1
]
!=
"
\n
"
)
i
+=
1
end
__printstr__
"
\n
"
if
len
==
0
nil
end
##
# Print human readable object description
#
# ISO 15.3.1.3.34
def
p
(
*
args
)
i
=
0
len
=
args
.
size
while
i
<
len
__printstr__
args
[
i
].
inspect
__printstr__
"
\n
"
i
+=
1
end
args
[
0
]
end
unless
Kernel
.
respond_to?
(
:sprintf
)
def
printf
(
*
args
)
raise
NotImplementedError
.
new
(
'printf not available'
)
end
def
sprintf
(
*
args
)
raise
NotImplementedError
.
new
(
'sprintf not available'
)
end
else
def
printf
(
*
args
)
__printstr__
(
sprintf
(
*
args
))
nil
end
end
end
mrbgems/mruby-print/src/print.c
0 → 100644
View file @
6954153f
#include "mruby.h"
#include "mruby/string.h"
#include <stdio.h>
static
void
printstr
(
mrb_state
*
mrb
,
mrb_value
obj
)
{
struct
RString
*
str
;
char
*
s
;
int
len
;
if
(
mrb_string_p
(
obj
))
{
str
=
mrb_str_ptr
(
obj
);
s
=
str
->
ptr
;
len
=
str
->
len
;
fwrite
(
s
,
len
,
1
,
stdout
);
}
}
/* 15.3.1.2.9 */
/* 15.3.1.3.34 */
mrb_value
mrb_printstr
(
mrb_state
*
mrb
,
mrb_value
self
)
{
mrb_value
argv
;
mrb_get_args
(
mrb
,
"o"
,
&
argv
);
printstr
(
mrb
,
argv
);
return
argv
;
}
void
mrb_mruby_print_gem_init
(
mrb_state
*
mrb
)
{
struct
RClass
*
krn
;
krn
=
mrb
->
kernel_module
;
mrb_define_method
(
mrb
,
krn
,
"__printstr__"
,
mrb_printstr
,
ARGS_REQ
(
1
));
}
void
mrb_mruby_print_gem_final
(
mrb_state
*
mrb
)
{
}
mrblib/print.rb
View file @
6954153f
...
...
@@ -3,78 +3,16 @@
#
# ISO 15.3.1
module
Kernel
unless
Kernel
.
respond_to?
(
:__printstr__
)
def
print
(
*
a
)
raise
NotImplementedError
.
new
(
'print not available'
)
end
def
puts
(
*
a
)
raise
NotImplementedError
.
new
(
'puts not available'
)
end
def
p
(
*
a
)
raise
NotImplementedError
.
new
(
'p not available'
)
end
def
printf
(
*
args
)
raise
NotImplementedError
.
new
(
'printf not available'
)
end
else
unless
Kernel
.
respond_to?
(
:sprintf
)
def
printf
(
*
args
)
raise
NotImplementedError
.
new
(
'printf not available'
)
end
def
sprintf
(
*
args
)
raise
NotImplementedError
.
new
(
'sprintf not available'
)
end
end
##
# Invoke method +print+ on STDOUT and passing +*args+
#
# ISO 15.3.1.2.10
def
print
(
*
args
)
i
=
0
len
=
args
.
size
while
i
<
len
__printstr__
args
[
i
].
to_s
i
+=
1
end
end
##
# Invoke method +puts+ on STDOUT and passing +*args*+
#
# ISO 15.3.1.2.11
def
puts
(
*
args
)
i
=
0
len
=
args
.
size
while
i
<
len
s
=
args
[
i
].
to_s
__printstr__
s
__printstr__
"
\n
"
if
(
s
[
-
1
]
!=
"
\n
"
)
i
+=
1
end
__printstr__
"
\n
"
if
len
==
0
nil
end
##
# Print human readable object description
#
# ISO 15.3.1.3.34
def
p
(
*
args
)
i
=
0
len
=
args
.
size
while
i
<
len
__printstr__
args
[
i
].
inspect
__printstr__
"
\n
"
i
+=
1
end
args
[
0
]
end
def
printf
(
*
args
)
__printstr__
(
sprintf
(
*
args
))
nil
end
def
print
(
*
a
)
raise
NotImplementedError
.
new
(
'print not available'
)
end
def
puts
(
*
a
)
raise
NotImplementedError
.
new
(
'puts not available'
)
end
def
p
(
*
a
)
raise
NotImplementedError
.
new
(
'p not available'
)
end
def
printf
(
*
args
)
raise
NotImplementedError
.
new
(
'printf not available'
)
end
end
src/init.c
View file @
6954153f
...
...
@@ -21,7 +21,6 @@ void mrb_init_hash(mrb_state*);
void
mrb_init_numeric
(
mrb_state
*
);
void
mrb_init_range
(
mrb_state
*
);
void
mrb_init_gc
(
mrb_state
*
);
void
mrb_init_print
(
mrb_state
*
);
void
mrb_init_math
(
mrb_state
*
);
void
mrb_init_mrblib
(
mrb_state
*
);
void
mrb_init_mrbgems
(
mrb_state
*
);
...
...
@@ -48,9 +47,6 @@ mrb_init_core(mrb_state *mrb)
mrb_init_numeric
(
mrb
);
DONE
;
mrb_init_range
(
mrb
);
DONE
;
mrb_init_gc
(
mrb
);
DONE
;
#ifdef ENABLE_STDIO
mrb_init_print
(
mrb
);
DONE
;
#endif
mrb_init_mrblib
(
mrb
);
DONE
;
#ifndef DISABLE_GEMS
mrb_init_mrbgems
(
mrb
);
DONE
;
...
...
src/print.c
View file @
6954153f
...
...
@@ -34,29 +34,6 @@ mrb_p(mrb_state *mrb, mrb_value obj)
#endif
}
/* 15.3.1.2.9 */
/* 15.3.1.3.34 */
mrb_value
mrb_printstr
(
mrb_state
*
mrb
,
mrb_value
self
)
{
mrb_value
argv
;
mrb_get_args
(
mrb
,
"o"
,
&
argv
);
printstr
(
mrb
,
argv
);
return
argv
;
}
void
mrb_init_print
(
mrb_state
*
mrb
)
{
struct
RClass
*
krn
;
krn
=
mrb
->
kernel_module
;
mrb_define_method
(
mrb
,
krn
,
"__printstr__"
,
mrb_printstr
,
ARGS_REQ
(
1
));
}
void
mrb_show_version
(
mrb_state
*
mrb
)
{
...
...
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