rucy 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ChangeLog ADDED
@@ -0,0 +1,8 @@
1
+ 2011-08-28 snori <snori@xord.org>
2
+
3
+ * v0.1.1
4
+
5
+
6
+ 2011-06-03 snori <snori@xord.org>
7
+
8
+ * delete Gemfile.
data/README CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  = Rucy - A Ruby C++ Extension Helper Library
3
3
 
4
- == by @tokujiros
4
+ == by snori@xord.org
data/Rakefile CHANGED
@@ -1,5 +1,8 @@
1
1
  # -*- mode: ruby; coding: utf-8 -*-
2
+
3
+
2
4
  $: << File.expand_path(File.dirname __FILE__)
5
+
3
6
  require 'rbconfig'
4
7
  require 'support'
5
8
 
@@ -14,9 +17,13 @@ TASKDIR = 'task'
14
17
 
15
18
  EXTEXT = RbConfig::CONFIG['DLEXT'] || 'so'
16
19
 
20
+ DEFS = %w[]
21
+ DEFS << 'WIN32' if win32?
22
+ DEFS << 'COCOA' if cocoa?
23
+
17
24
  incroot = RbConfig::CONFIG['rubyhdrdir']
18
25
  INCDIRS = [
19
- 'include',
26
+ File.expand_path('include'),
20
27
  incroot,
21
28
  "#{incroot}/#{RUBY_PLATFORM}",
22
29
  '/opt/local/include',
@@ -27,14 +34,19 @@ RBS = glob '**/*.rb'
27
34
 
28
35
  RUBY = ENV['RUBY'] || 'ruby'
29
36
  GEM = ENV['GEM'] || 'gem'
37
+ GIT = ENV['GIT'] || 'git'
30
38
  MAKE = ENV['MAKE'] || 'make'
31
39
  CC = RbConfig::CONFIG['CC'] || ENV['CC'] || 'g++'
32
- CFLAGS = '-Wall -O'
40
+ CFLAGS = '-Wall -O' + DEFS.map{|s| " -D#{s}"}.join
33
41
  AR = ENV['AR'] || 'ar'
34
42
  ARFLAGS = 'crs'
35
43
 
36
44
 
37
- task :default => :ext
45
+ task :default => :build
46
+
47
+ task :build => :ext
48
+
49
+ task :rebuild => [:clean, :build]
38
50
 
39
51
  task :lib => 'lib:build'
40
52
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/ext/rucy/extconf.rb CHANGED
@@ -1,50 +1,51 @@
1
1
  # -*- coding: utf-8 -*-
2
+
3
+
2
4
  %w[../../lib].each do |path|
3
5
  $: << File.expand_path(File.join File.dirname(__FILE__), *path.split('/'))
4
6
  end
7
+
5
8
  require 'rubygems'
6
9
  require 'mkmf'
7
- require 'rucy'
10
+ require 'rucy/module'
8
11
 
9
12
 
10
- DEBUG = ENV["DEBUG"] || false
13
+ DEBUG = ENV['DEBUG'] || false
11
14
 
12
15
  DEFS = []
13
16
  INCDIRS = %w[/opt/local/include /opt/include]
14
17
  LIBDIRS = []
15
18
 
16
19
  HEADERS = %w[
17
- boost/noncopyable.hpp
18
- ruby.h
19
- rucy.h
20
+ boost/noncopyable.hpp
21
+ ruby.h
22
+ rucy.h
20
23
  ]
21
24
  LIBS = %w[stdc++ rucy]
22
25
 
23
26
 
24
- DEFS << "_DEBUG" if DEBUG
27
+ DEFS << '_DEBUG' if DEBUG
25
28
 
26
29
  case RUBY_PLATFORM
27
- when /cygwin/
28
- DEFS << "WIN32" << "WINDOWS" << "CYGWIN"
29
- when /mswin/
30
- DEFS << "WIN32" << "WINDOWS"
30
+ when /mswin|ming|cygwin/
31
+ DEFS << 'WINDOWS' << 'WIN32' << $~[0].upcase
31
32
  when /darwin/
32
- DEFS << "COCOA"
33
+ DEFS << 'COCOA'
33
34
  end
34
35
 
35
- $CPPFLAGS << DEFS.map {|s| " -D#{s}"}.join
36
- $CPPFLAGS << INCDIRS.map {|s| " -I#{s}"}.join
37
- $LDFLAGS << LIBDIRS.map {|s| " -L#{s}"}.join
38
- $LOCAL_LIBS << " -lrucy"
36
+ $CPPFLAGS << DEFS.map {|s| " -D#{s}"}.join
37
+ $CPPFLAGS << INCDIRS.map {|s| " -I#{s}"}.join
38
+ $LDFLAGS << LIBDIRS.map {|s| " -L#{s}"}.join
39
+ $LOCAL_LIBS << ' -lrucy'
39
40
 
40
- dir_config "boost"
41
- dir_config "rucy", Rucy.root_dir
41
+ dir_config 'boost'
42
+ dir_config 'rucy', Rucy.root_dir
42
43
 
43
44
 
44
- Config::CONFIG.each {|key, val| val.gsub!(/gcc/, "g++")}
45
+ Config::CONFIG.each {|key, val| val.gsub!(/gcc/, 'g++')}
45
46
 
46
47
  exit 1 unless HEADERS.all? {|s| have_header(s)}
47
48
  exit 1 unless LIBS.all? {|s| have_library(s)}
48
49
 
49
50
 
50
- create_makefile "rucy/tester"
51
+ create_makefile 'rucy/tester'
@@ -16,6 +16,12 @@ namespace Rucy
16
16
  Class native_error_class ();
17
17
  // class Rucy::NativeError < RuntimeError
18
18
 
19
+ Class system_error_class ();
20
+ // class Rucy::SystemError < Rucy::NativeError
21
+
22
+ Class invalid_object_error_class ();
23
+ // class Rucy::InvalidObjectError < Rucy::NativeError
24
+
19
25
 
20
26
  void error (const char* format, ...);
21
27
 
@@ -26,13 +32,19 @@ namespace Rucy
26
32
 
27
33
  void argument_error (const char* format = NULL, ...);
28
34
 
29
- void argument_error (
35
+ void arg_count_error (
30
36
  const char* method, int nargs, int nargs_expected,
31
- int n1 = -1, int n2 = -1, int n3 = -1, int n4 = -1, int n5 = -1);
37
+ int n1 = -1, int n2 = -1, int n3 = -1, int n4 = -1, int n5 = -1,
38
+ int n6 = -1, int n7 = -1, int n8 = -1, int n9 = -1, int n10 = -1);
32
39
 
33
40
  void not_implemented_error (const char* format = NULL, ...);
34
41
 
35
42
 
43
+ void system_error (const char* format = NULL, ...);
44
+
45
+ void invalid_object_error (const char* format = NULL, ...);
46
+
47
+
36
48
  class RubyException : public std::runtime_error
37
49
  {
38
50
 
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ module Rucy
5
+
6
+
7
+ extend module ClassMethods
8
+
9
+ def root_dir ()
10
+ File.expand_path(File.join File.dirname(__FILE__), '..', '..')
11
+ end
12
+
13
+ def include_dirs ()
14
+ [File.join(root_dir, 'include')]
15
+ end
16
+
17
+ def library_dirs ()
18
+ [File.join(root_dir, 'lib')]
19
+ end
20
+
21
+ def version ()
22
+ open(File.join root_dir, 'VERSION') {|f| f.readline.chomp}
23
+ end
24
+
25
+ self
26
+
27
+ end# ClassMethods
28
+
29
+
30
+ end# Rucy
data/lib/rucy.rb CHANGED
@@ -1,24 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
 
4
- module Rucy
5
-
6
-
7
- def self.root_dir ()
8
- File.expand_path(File.join File.dirname(__FILE__), '..')
9
- end
10
-
11
- def self.include_dirs ()
12
- [File.join(root_dir, 'include')]
13
- end
14
-
15
- def self.library_dirs ()
16
- [File.join(root_dir, 'lib')]
17
- end
18
-
19
- def self.version ()
20
- open(File.join root_dir, 'VERSION') {|f| f.readline.chomp}
21
- end
22
-
23
-
24
- end# Rucy
4
+ require 'rucy/module'
data/rucy.gemspec CHANGED
@@ -1,14 +1,16 @@
1
1
  # -*- mode: ruby; coding: utf-8 -*-
2
+
3
+
2
4
  $: << File.join(File.dirname(__FILE__), 'lib')
5
+
3
6
  require 'rake'
4
7
  require 'rucy'
5
8
 
6
9
 
7
10
  FILES = FileList[*%w[
8
11
  README
12
+ ChangeLog
9
13
  Rakefile
10
- Gemfile
11
- Gemfile.lock
12
14
  support.rb
13
15
  rucy.gemspec
14
16
  VERSION
@@ -29,15 +31,15 @@ Gem::Specification.new do |s|
29
31
  s.description = 'This library helps you to develop Ruby Extension by C++.'
30
32
  s.version = Rucy.version
31
33
 
32
- s.authors = %w[@tokujiros]
33
- s.email = 'tokujiros@gmail.com'
34
- s.homepage = 'http://xord.tumblr.com/'
34
+ s.authors = %w[snori]
35
+ s.email = 'snori@xord.org'
36
+ s.homepage = 'http://blog.xord.org/'
35
37
 
36
38
  s.platform = Gem::Platform::RUBY
37
39
  s.required_ruby_version = '>=1.9.0'
38
40
  s.require_paths << 'ext'
39
41
 
40
- s.add_dependency 'rake'
42
+ s.add_development_dependency 'rake'
41
43
  s.add_development_dependency 'gemcutter'
42
44
 
43
45
  s.files = FILES.to_a
data/src/exception.cpp CHANGED
@@ -6,6 +6,10 @@
6
6
  #include <rucy/rucy.h>
7
7
  #include <rucy/string.h>
8
8
 
9
+ #ifdef WIN32
10
+ #include <windows.h>
11
+ #endif
12
+
9
13
 
10
14
  #define VA_STRING(format, result) \
11
15
  String result; \
@@ -34,6 +38,22 @@ namespace Rucy
34
38
  return c;
35
39
  }
36
40
 
41
+ Class
42
+ system_error_class ()
43
+ {
44
+ static Class c =
45
+ rucy_module().define_class("SystemError", native_error_class());
46
+ return c;
47
+ }
48
+
49
+ Class
50
+ invalid_object_error_class ()
51
+ {
52
+ static Class c =
53
+ rucy_module().define_class("InvalidObjectError", native_error_class());
54
+ return c;
55
+ }
56
+
37
57
 
38
58
  void
39
59
  error (const char* format, ...)
@@ -65,15 +85,16 @@ namespace Rucy
65
85
  }
66
86
 
67
87
  void
68
- argument_error (
88
+ arg_count_error (
69
89
  const char* method, int nargs, int nargs_expected,
70
- int n1, int n2, int n3, int n4, int n5)
90
+ int n1, int n2, int n3, int n4, int n5,
91
+ int n6, int n7, int n8, int n9, int n10)
71
92
  {
72
93
  String message = stringf(
73
94
  "wrong number of arguments for %s: %d for %d",
74
95
  method, nargs, nargs_expected);
75
96
 
76
- int n[5] = {n1, n2, n3, n4, n5};
97
+ int n[10] = {n1, n2, n3, n4, n5, n6, n7, n8, n9, n10};
77
98
  for (int i = 0; i < 5 && n[i] >= 0; ++i)
78
99
  message += stringf(" or %d", n[i]);
79
100
 
@@ -89,6 +110,42 @@ namespace Rucy
89
110
  }
90
111
 
91
112
 
113
+ void
114
+ system_error (const char* format, ...)
115
+ {
116
+ VA_STRING(format, message);
117
+
118
+ #ifdef WIN32
119
+ DWORD lasterror = GetLastError();
120
+ if (lasterror != 0)
121
+ {
122
+ LPVOID msg = NULL;
123
+ DWORD flags =
124
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
125
+ FORMAT_MESSAGE_FROM_SYSTEM |
126
+ FORMAT_MESSAGE_IGNORE_INSERTS;
127
+ if (FormatMessageA(
128
+ flags, NULL, lasterror, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
129
+ (LPSTR) &msg, 0, NULL))
130
+ {
131
+ String s = (LPCSTR) msg;
132
+ if (!s.empty()) message = s + ": " + message;
133
+ }
134
+ LocalFree(msg);
135
+ }
136
+ #endif
137
+
138
+ raise(system_error_class(), message.c_str());
139
+ }
140
+
141
+ void
142
+ invalid_object_error (const char* format, ...)
143
+ {
144
+ VA_STRING(format, message);
145
+ raise(invalid_object_error_class(), message.c_str());
146
+ }
147
+
148
+
92
149
  RubyException::RubyException (Value exception)
93
150
  : Super(""), val(exception)
94
151
  {
data/support.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
+
3
+
2
4
  require 'erb'
3
5
  require 'pp'
4
6
 
@@ -40,7 +42,7 @@ end
40
42
 
41
43
  def convertions (paths, convs)
42
44
  raise "empty conversion." if convs.empty?
43
- paths.map! do |path|
45
+ paths = paths.map do |path|
44
46
  convpath = path
45
47
  convs.each do |from, to|
46
48
  convpath = convpath.sub(/#{from.gsub('.', '\.')}$/, to)
@@ -52,7 +54,15 @@ end
52
54
 
53
55
  alias sh_original sh
54
56
 
55
- def sh (s)
56
- sh_original s
57
+ def sh (*args)
58
+ sh_original *args
57
59
  #rescue
58
60
  end
61
+
62
+ def win32? ()
63
+ RUBY_PLATFORM =~ /mswin|ming|cygwin/
64
+ end
65
+
66
+ def cocoa? ()
67
+ RUBY_PLATFORM =~ /darwin/
68
+ end
data/task/ext.rake CHANGED
@@ -10,27 +10,28 @@ namespace :ext do
10
10
 
11
11
  extconf = File.join dir, "extconf.rb"
12
12
  makefile = File.join dir, "Makefile"
13
- depends = File.join dir, "depends"
13
+ depend = File.join dir, "depend"
14
14
 
15
15
  cpps = Dir.glob("#{dir}/**/*.cpp")
16
16
 
17
- task :build => out
17
+ task :build => makefile do
18
+ sh %( cd #{dir} && #{MAKE} )
19
+ end
18
20
 
19
21
  task :clean do
20
22
  sh %( cd #{dir} && #{MAKE} clean ) if File.exist? makefile
21
- sh %( rm -f #{makefile} #{depends} )
22
- end
23
-
24
- file out => makefile do
25
- sh %( cd #{dir} && #{MAKE} )
23
+ sh %( rm -f #{makefile} #{depend} )
26
24
  end
27
25
 
28
- file makefile => [extconf, "lib:build"] do #, depends] do
26
+ file makefile => [extconf, depend] do
29
27
  sh %( cd #{dir} && #{RUBY} #{File.basename extconf} )
30
28
  end
31
29
 
32
- file depends => cpps do
33
- sh %( cd #{dir} && touch #{depends} )
30
+ file depend => ["lib:build"] + cpps do
31
+ incdirs = INCDIRS.map{|s| " -I#{s}"}.join
32
+ srcs = cpps.map{|cpp| File.basename cpp}.join ' '
33
+ dep = File.basename depend
34
+ sh %( cd #{dir} && #{CC} -M #{CFLAGS} #{incdirs} #{srcs} > #{dep} )
34
35
  end
35
36
 
36
37
  end# :ext
data/task/git.rake ADDED
@@ -0,0 +1,22 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+
3
+
4
+ namespace :git do
5
+
6
+ task :status do
7
+ sh %( #{GIT} status )
8
+ end
9
+
10
+ task :diff do
11
+ sh %( #{GIT} diff | cat )
12
+ end
13
+
14
+ task :push do
15
+ sh %( #{GIT} push )
16
+ end
17
+
18
+ task :pull do
19
+ sh %( #{GIT} pull )
20
+ end
21
+
22
+ end# :git
data/task/lib.rake CHANGED
@@ -1,6 +1,9 @@
1
1
  # -*- mode: ruby; coding: utf-8 -*-
2
2
 
3
3
 
4
+ require 'rake/loaders/makefile'
5
+
6
+
4
7
  namespace :lib do
5
8
 
6
9
  name = NAME
@@ -11,8 +14,12 @@ namespace :lib do
11
14
  headers = glob("include/**/*.h") | erbs.values.grep(/\.h$/)
12
15
  srcs = glob("src/**/*.cpp") | erbs.values.grep(/\.cpp$/)
13
16
 
14
- objs = convertions srcs, {".cpp" => ".o"}
15
- tmps = objs.values | erbs.values
17
+ depend = 'depend.mf'
18
+ objs = convertions srcs, {".cpp" => ".o"}
19
+ tmps = (objs.values | erbs.values) + [depend]
20
+
21
+ cflags = CFLAGS.dup
22
+ cflags << INCDIRS.map{|s| " -I#{s}"}.join
16
23
 
17
24
  task :build => out
18
25
 
@@ -28,11 +35,19 @@ namespace :lib do
28
35
  sh %( #{AR} #{ARFLAGS} #{out} #{objs.values.join " "} )
29
36
  end
30
37
 
31
- objs.each do |(src, obj)|
32
- incdirs = INCDIRS.map{|s| " -I#{s}"}.join
38
+ file depend => 'lib:erb' do
39
+ sh %( #{CC} -M #{cflags} #{srcs.join ' '} > #{depend} )
40
+ input = open(depend) {|f| f.read}
41
+ open(depend, 'w') do |output|
42
+ output << input.gsub(/\w+\.o/, SRCDIR + '/\0')
43
+ end
44
+ end
33
45
 
34
- file obj => [src] + erbs.values do
35
- sh %( #{CC} -c #{CFLAGS} #{incdirs} -o #{obj} #{src} )
46
+ import depend if File.exist? depend
47
+
48
+ objs.each do |(src, obj)|
49
+ file obj => [depend, src] + erbs.values do
50
+ sh %( #{CC} -c #{cflags} -o #{obj} #{src} )
36
51
  end
37
52
  end
38
53
 
data/test/test_rucy.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  # -*- coding: utf-8 -*-
2
+
3
+
2
4
  $: << File.expand_path(File.join File.dirname(__FILE__), "..", "ext")
5
+
3
6
  require 'test/unit'
4
7
  require 'rucy/tester'
5
8
 
metadata CHANGED
@@ -2,15 +2,15 @@
2
2
  name: rucy
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
- - "@tokujiros"
8
+ - snori
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-10 00:00:00 Z
13
+ date: 2011-08-28 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -21,7 +21,7 @@ dependencies:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
- type: :runtime
24
+ type: :development
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: gemcutter
@@ -35,7 +35,7 @@ dependencies:
35
35
  type: :development
36
36
  version_requirements: *id002
37
37
  description: This library helps you to develop Ruby Extension by C++.
38
- email: tokujiros@gmail.com
38
+ email: snori@xord.org
39
39
  executables: []
40
40
 
41
41
  extensions:
@@ -44,14 +44,14 @@ extra_rdoc_files:
44
44
  - README
45
45
  files:
46
46
  - README
47
+ - ChangeLog
47
48
  - Rakefile
48
- - Gemfile
49
- - Gemfile.lock
50
49
  - support.rb
51
50
  - rucy.gemspec
52
51
  - VERSION
53
52
  - task/ext.rake
54
53
  - task/gem.rake
54
+ - task/git.rake
55
55
  - task/lib.rake
56
56
  - ext/rucy/extconf.rb
57
57
  - ext/rucy/tester.cpp
@@ -70,6 +70,7 @@ files:
70
70
  - include/rucy/function.h.erb
71
71
  - include/rucy/module.h.erb
72
72
  - include/rucy/value.h.erb
73
+ - lib/rucy/module.rb
73
74
  - lib/rucy.rb
74
75
  - src/class.cpp
75
76
  - src/exception.cpp
@@ -84,7 +85,7 @@ files:
84
85
  - src/module.cpp.erb
85
86
  - src/value.cpp.erb
86
87
  - test/test_rucy.rb
87
- homepage: http://xord.tumblr.com/
88
+ homepage: http://blog.xord.org/
88
89
  licenses: []
89
90
 
90
91
  post_install_message:
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source "http://rubygems.org"
2
- gem "rake"
3
- gem "gemcutter"
data/Gemfile.lock DELETED
@@ -1,12 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- gemcutter (0.7.0)
5
- rake (0.8.7)
6
-
7
- PLATFORMS
8
- ruby
9
-
10
- DEPENDENCIES
11
- gemcutter
12
- rake