Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripting with mruby #848

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2bccf4f
Add reval command interface
tricknotes Nov 22, 2012
d213cbe
Compile with mruby
tricknotes Nov 22, 2012
7cbd470
Disable stdio for mruby
tricknotes Dec 20, 2012
a6a5b4a
Evaluate first argument with mruby
tricknotes Nov 22, 2012
440143f
Support type cast
tricknotes Nov 24, 2012
a7dcd73
Handle mruby error
tricknotes Nov 25, 2012
9d0a842
Handle mruby nil
tricknotes Nov 25, 2012
05470c5
Handle mruby hash
tricknotes Nov 25, 2012
e0188b7
Update src/Makefile.dep
tricknotes Dec 10, 2012
bd3b750
Define ARGV
tricknotes Nov 29, 2012
c0f52a3
Define KEYS
tricknotes Nov 29, 2012
2b1c6f7
Set constants of ARGV
tricknotes Nov 29, 2012
c14acfc
Add check for argc
tricknotes Nov 29, 2012
aef385b
Handle syntax error
tricknotes Nov 29, 2012
ca474a4
Add mruby object `REDIS` for redis interface
tricknotes Dec 1, 2012
cd4c990
Parse redis object to mruby object
tricknotes Dec 2, 2012
d1d1f0e
Return error when `REDIS.call` called with no argument
tricknotes Dec 4, 2012
f631e61
Check argument for redis command
tricknotes Dec 6, 2012
795a9ec
Extract error handling
tricknotes Dec 6, 2012
4ec09b8
Apply `zfree`
tricknotes Dec 6, 2012
445d05a
Skip cleanup when argument isn't given
tricknotes Dec 13, 2012
a53642b
Deny command that is not allowed from scripts
tricknotes Dec 6, 2012
32b9a53
Check argument type
tricknotes Dec 7, 2012
4463464
Return error if mruby object is recursive
tricknotes Dec 11, 2012
9edc859
Support mruby float as a redis integer
tricknotes Dec 22, 2012
7536ad6
Support mruby boolean as a redis type
tricknotes Dec 11, 2012
2d371d4
Add tests about mruby
tricknotes Dec 11, 2012
386fa8e
Add test about type conversion (redis -> mruby)
tricknotes Dec 12, 2012
e00cbdc
Add test about `REDIS.call` in mruby
tricknotes Dec 13, 2012
f6afde1
Add test about mruby error
tricknotes Dec 13, 2012
5a3aae7
Add test about recursive mruby object
tricknotes Dec 17, 2012
4a09195
Support redis status in mruby
tricknotes Dec 15, 2012
5f6963c
Stop force string
tricknotes Dec 15, 2012
a5851f6
Add mruby script function `REDIS.pcall`
tricknotes Dec 21, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion deps/Makefile
Expand Up @@ -37,6 +37,7 @@ distclean:
-(cd linenoise && $(MAKE) clean) > /dev/null || true
-(cd lua && $(MAKE) clean) > /dev/null || true
-(cd jemalloc && [ -f Makefile ] && $(MAKE) distclean) > /dev/null || true
-(cd mruby && ./minirake clean) > /dev/null || true
-(rm -f .make-*)

.PHONY: distclean
Expand Down Expand Up @@ -67,7 +68,16 @@ lua: .make-prerequisites

.PHONY: lua

JEMALLOC_CFLAGS= -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops $(CFLAGS)
MRUBY_CFLAGS+= -DDISABLE_STDIO $(CFLAGS)
MRUBY_LDFLAGS+= $(LDFLAGS)

mruby: .make-prerequisites
@printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR)
cd mruby && $(MAKE) CFLAGS="$(MRUBY_CFLAGS)" MYLDFLAGS="$(MRUBY_LDFLAGS)"

.PHONY: mruby

JEMALLOC_CFLAGS= --Wall -pipe -g3 -O3 -funroll-loops $(CFLAGS)
JEMALLOC_LDFLAGS= $(LDFLAGS)

jemalloc: .make-prerequisites
Expand Down
39 changes: 39 additions & 0 deletions deps/mruby/.gitignore
@@ -0,0 +1,39 @@
# /
*.bak
*.dylib
*.inc
*.o
*.a
*.orig
*.rej
*.sav
*.swp
*.d
*.tmp
*.ctmp
*.rbtmp
*~
.DS_Store
.ccmalloc
.svn
/.git
cscope.out
/src/y.tab.c
/bin
/mrblib/mrblib.c
/mrblib/*.*tmp
/mrblib/mrblib.mrb
/test/mrbtest
/test/mrbtest.c
/test/*.*tmp
/test/mrubytest.*
tools/mrbc/mrbc.mrb
CMakeFiles
CMakeCache.txt
/mrbgems/generator
/mrbgems/gem_init.c
/mrbgems/g/Makefile
/mrbgems/g/MakefileGemList
/mrbgems/g/mrbgemtest.ctmp
/mrbgems/g/mrbgemtest.rbtmp
/mrbgems/g/*/gem_srclib.c
3 changes: 3 additions & 0 deletions deps/mruby/.travis.yml
@@ -0,0 +1,3 @@
# no installation...

script: "./minirake all test"
12 changes: 12 additions & 0 deletions deps/mruby/AUTHORS
@@ -0,0 +1,12 @@
Original Authors "mruby developers" are:
Yukihiro Matsumoto
FUKUOKA CSK CORPORATION
Kyushu Institute of Technology
Network Applied Communication Laboratory, Inc.
Daniel Bovensiepen
Jon Maken
Bjorn De Meyer
Yuichiro MASUI
Masamitsu MURASE
Masaki Muranaka
Internet Initiative Japan Inc.
110 changes: 110 additions & 0 deletions deps/mruby/CMakeLists.txt
@@ -0,0 +1,110 @@
# CMake build system for mruby
# License: released under the same license as mruby
# Author: jonforums@gmail.com
# Author: beoran@gmail.com
#
# Usage example:
# 1. Ensure CMake, Bison, and a build toolchain are on `PATH`
# 2. Change to a build directory outside source tree, eg - `build` subdir
# 3. Create build Makefiles or project files.
# `cmake ..` (UNIX-like system)
# `cmake -G "MSYS Makefiles" ..`
# `cmake -G "Visual Studio 10" ..`
# `cmake -G "NMake Makefiles" ..`
# ** to cross-compile: add -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain/file
# ** to set install dir: add -DCMAKE_INSTALL_PREFIX=/path/to/installdir
# 4a. Build: `make` (to make noisy, add `VERBOSE=1`)
# 4b. Build and test: `make all test`
# 4c. Build, test, and install: `make all test install`
# 4d. Build, test, and package: `make all test package`

cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)

# Default build mode is Release With Debug Info unless specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Choose build type: empty Debug Release RelWithDebInfo MinSizeRel"
FORCE)
message(STATUS "Build type not set, defaulting to 'RelWithDebInfo'")
endif()

project(mruby C)

# TODO stop polluting source tree with CMakeFiles/ and CMakeCache.txt
# on build location check failure
# Make sure we are not trying to generate in in-tree build unless building
# with an MSVC or Xcode IDE where it's OK.
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT (MSVC_IDE OR XCODE))
message(FATAL_ERROR
"\nIn-source builds are not allowed as CMake would overwrite the "
"Makefiles distributed with mruby. Delete any created 'CMakeFiles' "
"subdirectory and 'CMakeCache.txt' file from the current directory, "
"change to the 'build' subdirectory, and re-run CMake from there.")
endif()

if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW) # don't split absolute link paths
cmake_policy(SET CMP0012 NEW) # recognize number & boolean literals
cmake_policy(SET CMP0015 NEW) # convert relative link paths to absolute
endif(COMMAND cmake_policy)

# Match original Makefile's default in-tree install.
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR} CACHE PATH
"Install path prefix prepended to install directories."
FORCE
)
endif()

# TODO refactor to use an option when adding shared lib support
set(BUILD_SHARED_LIBS OFF)

# Version of mruby, useful for versoning .so and .dll files.
# TODO automate by parsing src/version.h -or- extract git info?
set(MRUBY_VERSION 1.0.0dev)
string(REGEX MATCH "^[0-9]+[.][0-9]+" MRUBY_SOVERSION ${MRUBY_VERSION})
string(REPLACE "." "" MRUBY_DLL_SHORTVER ${MRUBY_SOVERSION})

# Search in the `cmake` directory for custom CMake helper modules.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
include(IntrospectSystem)

# Search for C header files in these directories.
include_directories("${CMAKE_SOURCE_DIR}/include" "${CMAKE_SOURCE_DIR}/src")

# TODO re-enable (and implement) if needed
# On some 64-bit platforms, libraries should be installed into `lib64'
# instead of `lib'. Set this to 64 to do that.
#set(LIB_SUFFIX "" CACHE STRING "Suffix for 'lib' directories, e.g. '64'")

# build the components
add_subdirectory(src)
add_subdirectory(mrblib)
add_subdirectory(tools)
add_subdirectory(test)

# install the header files
install(FILES include/mruby.h DESTINATION include)
install(FILES include/mrbconf.h DESTINATION include)
install(DIRECTORY include/mruby DESTINATION include FILES_MATCHING PATTERN "*.h")

# TODO refactor once proper versioning scheme implemented
# archive packaging
set(CPACK_GENERATOR "TGZ;ZIP")
string(TOLOWER ${CMAKE_SYSTEM_NAME} MRUBY_HOST)
if(CMAKE_C_COMPILER_VERSION)
string(REPLACE "." "" MRUBY_GCC_VERSION ${CMAKE_C_COMPILER_VERSION})
endif()

# TODO add build info suffix for non-Windows builds?
if(MINGW)
set(MRUBY_BUILD "-mingw${MRUBY_GCC_VERSION}")
elseif(MSVC)
set(MRUBY_BUILD "-msvc${MSVC_VERSION}")
endif()
set(CPACK_PACKAGE_FILE_NAME
"${CMAKE_PROJECT_NAME}-${MRUBY_VERSION}-${MRUBY_HOST}${MRUBY_BUILD}"
)
include(CPack)

# vim: ts=2 sts=2 sw=2 et
65 changes: 65 additions & 0 deletions deps/mruby/CONTRIBUTING.md
@@ -0,0 +1,65 @@
# How to contribute

mruby is an open-source project which is looking forward to each contribution.

## Your Pull Request

To make it easy to review and understand your change please keep the following
things in mind before submitting your pull request:

* Work on the latest possible state of **mruby/master**
* Test your changes before creating a pull request (**make test**)
* If possible write a test case which confirms your change
* Don't mix several features or bug-fixes in one pull request
* Create a branch which is dedicated to your change
* Create a meaningful commit message
* Explain your change (i.e. with a link to the issue you are fixing)

## Coding conventions

How to style your C and Ruby code which you want to submit.

### C code

The core part (parser, bytecode-interpreter, core-lib, etc.) of mruby is
written in the C programming language. Please note the following hints for your
C code:

#### Comply with C99 (ISO/IEC 9899:1999)

mruby should be highly portable to other systems and compilers. For that it is
recommended to keep your code as close as possible to the C99 standard
(http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf).

Although we target C99, VC is also an important target for mruby, so that we
avoid local variable declaration in the middle.

#### Reduce library dependencies to a minimum

The dependencies to libraries should be put to an absolute minimum. This
increases the portability but makes it also easier to cut away parts of mruby
on-demand.

#### Don't use C++ style comments

/* This is the prefered comment style */

Use C++ style comments only for temporary comment e.g. commenting out some code lines.

#### Insert a break after the method return value:

int
main(void)
{
...
}

### Ruby code

Parts of the standard library of mruby is written in the Ruby programming language
itself. Please note the following hints for your Ruby code:

#### Comply with the Ruby standard (ISO/IEC 30170:2012)

mruby is currently targeting to execute Ruby code which complies to ISO/IEC
30170:2012 (http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=59579).
15 changes: 15 additions & 0 deletions deps/mruby/ChangeLog
@@ -0,0 +1,15 @@
Thu Apl 19 17:25:18 2012 Yukihiro Matsumoto <matz@ruby-lang.org>

* first release version 1.0.0 released.

Local variables:
add-log-time-format: (lambda ()
(let* ((time (current-time))
(system-time-locale "C")
(diff (+ (cadr time) 32400))
(lo (% diff 65536))
(hi (+ (car time) (/ diff 65536))))
(format-time-string "%a %b %e %H:%M:%S %Y" (list hi lo) t)))
indent-tabs-mode: t
tab-width: 8
end:
29 changes: 29 additions & 0 deletions deps/mruby/INSTALL
@@ -0,0 +1,29 @@
* Prerequisites

1. Make sure you have bison (http://www.gnu.org/software/bison/) installed in your system.
2. Make sure you have ruby installed in your system (required to build).

* Compilation and Installation

1. Run make in the top directory.

This command will create the following directories and
store libraries and binaries files into them.

* bin
* lib
* include

You can directory invoke 'minirake' as the following.

$ ruby ./minirake

If an error occurs when compiling mruby, it will be helpful for others if you
send a detailed report to the developers that includes the error log, machine,
and OS type.


* Porting to other platforms


That's all.
8 changes: 8 additions & 0 deletions deps/mruby/LEGAL
@@ -0,0 +1,8 @@
LEGAL NOTICE INFORMATION
------------------------

All the files in this distribution are covered under the MIT license
(see the file MITL) except some files mentioned below:


(Currently no items are listed.)
20 changes: 20 additions & 0 deletions deps/mruby/MITL
@@ -0,0 +1,20 @@
Copyright (c) 2012 mruby developers

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.

21 changes: 21 additions & 0 deletions deps/mruby/Makefile
@@ -0,0 +1,21 @@
# mruby is using Rake (http://rake.rubyforge.org) as a build tool.
# We provide a minimalistic version called minirake inside of our
# codebase.

RAKE = ruby ./minirake

.PHONY : all
all :
$(RAKE)

.PHONY : test
test :
$(RAKE) test

.PHONY : clean
clean :
$(RAKE) clean

.PHONY : showconfig
showconfig :
$(RAKE) showconfig
13 changes: 13 additions & 0 deletions deps/mruby/NEWS
@@ -0,0 +1,13 @@
* NEWS

This document is a list of user visible feature changes made between
releases except for bug fixes.

Note that each entry is kept so brief that no reason behind or
reference information is supplied with. For a full list of changes
with all sufficient information, see the ChangeLog file.


** Information about first release v1.0.0