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
44fdd53f
Commit
44fdd53f
authored
Sep 05, 2018
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `mruby-sleep` gem to the core.
parent
b01b0d24
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
288 additions
and
0 deletions
+288
-0
mrbgems/mruby-sleep/.gitignore
mrbgems/mruby-sleep/.gitignore
+4
-0
mrbgems/mruby-sleep/.travis.yml
mrbgems/mruby-sleep/.travis.yml
+29
-0
mrbgems/mruby-sleep/.travis_build_config.rb
mrbgems/mruby-sleep/.travis_build_config.rb
+6
-0
mrbgems/mruby-sleep/README.md
mrbgems/mruby-sleep/README.md
+27
-0
mrbgems/mruby-sleep/Rakefile
mrbgems/mruby-sleep/Rakefile
+29
-0
mrbgems/mruby-sleep/example/sleep.rb
mrbgems/mruby-sleep/example/sleep.rb
+3
-0
mrbgems/mruby-sleep/mrbgem.rake
mrbgems/mruby-sleep/mrbgem.rake
+5
-0
mrbgems/mruby-sleep/src/mrb_sleep.c
mrbgems/mruby-sleep/src/mrb_sleep.c
+137
-0
mrbgems/mruby-sleep/src/mrb_sleep.h
mrbgems/mruby-sleep/src/mrb_sleep.h
+12
-0
mrbgems/mruby-sleep/test/sleep_test.rb
mrbgems/mruby-sleep/test/sleep_test.rb
+36
-0
No files found.
mrbgems/mruby-sleep/.gitignore
0 → 100644
View file @
44fdd53f
/mruby
*.so
*.a
\ No newline at end of file
mrbgems/mruby-sleep/.travis.yml
0 → 100644
View file @
44fdd53f
dist
:
trusty
language
:
c
compiler
:
-
gcc
-
clang
env
:
-
MRUBY_VERSION=1.2.0
-
MRUBY_VERSION=master
matrix
:
allow_failures
:
-
env
:
MRUBY_VERSION=master
branches
:
only
:
-
master
addons
:
apt
:
packages
:
-
rake
-
bison
-
git
-
gperf
# - aclocal
# - automake
# - autoconf
# - autotools-dev
script
:
-
rake test
\ No newline at end of file
mrbgems/mruby-sleep/.travis_build_config.rb
0 → 100644
View file @
44fdd53f
MRuby
::
Build
.
new
do
|
conf
|
toolchain
:gcc
conf
.
gembox
'default'
conf
.
gem
'../mruby-sleep'
conf
.
enable_test
end
mrbgems/mruby-sleep/README.md
0 → 100644
View file @
44fdd53f
# Sleep Module for mruby
mruby sleep module
## install by mrbgems
-
add conf.gem line to
`build_config.rb`
```
ruby
MRuby
::
Build
.
new
do
|
conf
|
# ... (snip) ...
conf
.
gem
:git
=>
'https://github.com/matsumoto-r/mruby-sleep.git'
end
```
## example
```
ruby
Sleep
::
sleep
(
10
)
Sleep
::
usleep
(
10000
)
```
# License
under the MIT License:
*
http://www.opensource.org/licenses/mit-license.php
mrbgems/mruby-sleep/Rakefile
0 → 100644
View file @
44fdd53f
MRUBY_CONFIG
=
File
.
expand_path
(
ENV
[
"MRUBY_CONFIG"
]
||
".travis_build_config.rb"
)
MRUBY_VERSION
=
ENV
[
"MRUBY_VERSION"
]
||
"1.2.0"
file
:mruby
do
cmd
=
"git clone --depth=1 git://github.com/mruby/mruby.git"
if
MRUBY_VERSION
!=
'master'
cmd
<<
" && cd mruby"
cmd
<<
" && git fetch --tags && git checkout $(git rev-parse
#{
MRUBY_VERSION
}
)"
end
sh
cmd
end
desc
"compile binary"
task
:compile
=>
:mruby
do
sh
"cd mruby && MRUBY_CONFIG=
#{
MRUBY_CONFIG
}
rake all"
end
desc
"test"
task
:test
=>
:mruby
do
sh
"cd mruby && MRUBY_CONFIG=
#{
MRUBY_CONFIG
}
rake all test"
end
desc
"cleanup"
task
:clean
do
exit
0
unless
File
.
directory?
(
'mruby'
)
sh
"cd mruby && rake deep_clean"
end
task
:default
=>
:compile
mrbgems/mruby-sleep/example/sleep.rb
0 → 100644
View file @
44fdd53f
Sleep
::
sleep
(
10
)
Sleep
::
usleep
(
10000
)
mrbgems/mruby-sleep/mrbgem.rake
0 → 100644
View file @
44fdd53f
MRuby
::
Gem
::
Specification
.
new
(
'mruby-sleep'
)
do
|
spec
|
spec
.
license
=
'MIT'
spec
.
authors
=
'MATSUMOTO Ryosuke'
spec
.
version
=
'0.0.1'
end
mrbgems/mruby-sleep/src/mrb_sleep.c
0 → 100644
View file @
44fdd53f
/*
** mrb_sleep - sleep class for mruby
**
** Copyright (c) mod_mruby developers 2012-
**
** Permission is hereby granted, free of charge, to any person obtaining
** a copy of this software and associated documentation files (the
** "Software"), to deal in the Software without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Software, and to
** permit persons to whom the Software is furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be
** included in all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**
** [ MIT license: http://www.opensource.org/licenses/mit-license.php ]
*/
#include <time.h>
#ifdef _WIN32
#include <windows.h>
#define sleep(x) Sleep(x * 1000)
#define usleep(x) Sleep(((x)<1000) ? 1 : ((x)/1000))
#else
#include <unistd.h>
#include <sys/time.h>
#endif
#include "mruby.h"
mrb_value
mrb_f_sleep_sleep
(
mrb_state
*
mrb
,
mrb_value
self
)
{
time_t
beg
,
end
;
mrb_value
*
argv
;
mrb_int
argc
;
int
iargc
;
beg
=
time
(
0
);
mrb_get_args
(
mrb
,
"*"
,
&
argv
,
&
argc
);
iargc
=
(
int
)
argc
;
/* not implemented forever sleep (called without an argument)*/
if
(
iargc
==
0
||
iargc
>=
2
)
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"wrong number of arguments"
);
}
if
(
mrb_fixnum_p
(
argv
[
0
])
&&
mrb_fixnum
(
argv
[
0
])
>=
0
)
{
sleep
(
mrb_fixnum
(
argv
[
0
]));
}
else
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"time interval must be positive integer"
);
}
end
=
time
(
0
)
-
beg
;
return
mrb_fixnum_value
(
end
);
}
mrb_value
mrb_f_usleep_usleep
(
mrb_state
*
mrb
,
mrb_value
self
)
{
mrb_int
argc
;
mrb_value
*
argv
;
#ifdef _WIN32
FILETIME
st_ft
,
ed_ft
;
unsigned
__int64
st_time
=
0
;
unsigned
__int64
ed_time
=
0
;
#else
struct
timeval
st_tm
,
ed_tm
;
#endif
time_t
slp_tm
;
#ifdef _WIN32
GetSystemTimeAsFileTime
(
&
st_ft
);
#else
gettimeofday
(
&
st_tm
,
NULL
);
#endif
mrb_get_args
(
mrb
,
"*"
,
&
argv
,
&
argc
);
/* not implemented forever sleep (called without an argument)*/
if
(
argc
==
0
||
argc
>=
2
)
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"wrong number of arguments"
);
}
if
(
mrb_fixnum_p
(
argv
[
0
])
&&
mrb_fixnum
(
argv
[
0
])
>=
0
)
{
usleep
(
mrb_fixnum
(
argv
[
0
]));
}
else
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"time interval must be positive integer"
);
}
#ifdef _WIN32
GetSystemTimeAsFileTime
(
&
ed_ft
);
st_time
|=
st_ft
.
dwHighDateTime
;
st_time
<<=
32
;
st_time
|=
st_ft
.
dwLowDateTime
;
ed_time
|=
ed_ft
.
dwHighDateTime
;
ed_time
<<=
32
;
ed_time
|=
ed_ft
.
dwLowDateTime
;
slp_tm
=
(
ed_time
-
st_time
)
/
10
;
#else
gettimeofday
(
&
ed_tm
,
NULL
);
if
(
st_tm
.
tv_usec
>
ed_tm
.
tv_usec
)
{
slp_tm
=
1000000
+
ed_tm
.
tv_usec
-
st_tm
.
tv_usec
;
}
else
{
slp_tm
=
ed_tm
.
tv_usec
-
st_tm
.
tv_usec
;
}
#endif
return
mrb_fixnum_value
(
slp_tm
);
}
void
mrb_mruby_sleep_gem_init
(
mrb_state
*
mrb
)
{
struct
RClass
*
sleep
;
sleep
=
mrb_define_module
(
mrb
,
"Sleep"
);
mrb_define_class_method
(
mrb
,
sleep
,
"sleep"
,
mrb_f_sleep_sleep
,
MRB_ARGS_REQ
(
1
));
mrb_define_class_method
(
mrb
,
sleep
,
"usleep"
,
mrb_f_usleep_usleep
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
mrb
->
kernel_module
,
"sleep"
,
mrb_f_sleep_sleep
,
MRB_ARGS_REQ
(
1
));
mrb_define_method
(
mrb
,
mrb
->
kernel_module
,
"usleep"
,
mrb_f_usleep_usleep
,
MRB_ARGS_REQ
(
1
));
}
void
mrb_mruby_sleep_gem_final
(
mrb_state
*
mrb
)
{
}
mrbgems/mruby-sleep/src/mrb_sleep.h
0 → 100644
View file @
44fdd53f
/*
// mrb_sleep.h - to provide sleep methods
//
// See Copyright Notice in mrb_sleep.c
*/
#ifndef MRB_SLEEP_H
#define MRB_SLEEP_H
void
mrb_mruby_sleep_gem_init
(
mrb_state
*
mrb
);
#endif
mrbgems/mruby-sleep/test/sleep_test.rb
0 → 100644
View file @
44fdd53f
def
run_with_catching_error
&
b
e
=
nil
begin
b
.
call
rescue
=>
_e
e
=
_e
end
return
e
end
assert
(
"sleep works"
)
do
e
=
run_with_catching_error
{
sleep
1
}
assert_nil
e
end
assert
(
"sleep would not accept negative value"
)
do
e
=
run_with_catching_error
{
sleep
-
1
}
assert_not_equal
e
,
nil
assert_equal
e
.
class
,
ArgumentError
end
assert
(
"usleep works"
)
do
e
=
run_with_catching_error
{
usleep
100
}
assert_nil
e
end
assert
(
"usleep would not accept negative value"
)
do
e
=
run_with_catching_error
{
usleep
-
100
}
assert_not_equal
e
,
nil
assert_equal
e
.
class
,
ArgumentError
end
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