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
b69761e2
Commit
b69761e2
authored
Mar 24, 2013
by
mattn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add mruby-print
parent
e53fa357
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
115 additions
and
0 deletions
+115
-0
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
No files found.
build_config.rb
View file @
b69761e2
...
...
@@ -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 @
b69761e2
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 @
b69761e2
##
# 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 @
b69761e2
#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
)
{
}
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