babascript 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +4 -0
- data/babascript.gemspec +1 -1
- data/bin/baba +1 -1
- data/bin/baba-vm +46 -0
- data/lib/babascript/baba.rb +28 -8
- data/lib/babascript/version.rb +1 -1
- data/lib/babascript.rb +2 -1
- data/samples/sample.bb +12 -5
- data/samples/sample.rb +2 -2
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1219669ef1f3883b038f307e2672c55f038e3e1d
|
4
|
+
data.tar.gz: 753b26e3e34eb229404aa9d178a5a682f621d282
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8edcfde5f3db9fe504092c2257e3db3440e7be49d920420664ede6c1b0ad77e8d8c8b91e3bfee8313bfb9c7994c9f05cf61c6a1c647fef7d44b8f68a19314e1
|
7
|
+
data.tar.gz: 03c5474907ee1ea3a69df6234cfe72b3f08c6f0f3e70dcaad80c70622b35e8be73b85aed69fe447ff630b32742a8724a4350025fb40bfb9278500b150edcfcf3
|
data/History.txt
CHANGED
data/babascript.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "
|
21
|
+
spec.add_dependency "em-rocketio-linda-client"
|
22
22
|
spec.add_dependency "json"
|
23
23
|
spec.add_dependency "args_parser"
|
24
24
|
|
data/bin/baba
CHANGED
data/bin/baba-vm
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
require 'rubygems'
|
4
|
+
require 'args_parser'
|
5
|
+
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
|
6
|
+
require 'em-rocketio-linda-client'
|
7
|
+
|
8
|
+
args = ArgsParser.parse ARGV do
|
9
|
+
arg :version, "show version", :alias => :v
|
10
|
+
arg :help, "show help", :alias => :h
|
11
|
+
end
|
12
|
+
|
13
|
+
binname = File.basename(__FILE__)
|
14
|
+
if args.has_option? :help
|
15
|
+
STDERR.puts "BabaScript VM v#{BabaScript::VERSION}"
|
16
|
+
STDERR.puts args.help
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
|
20
|
+
if args.has_option? :version
|
21
|
+
STDERR.puts "BabaScript v#{BabaScript::VERSION} - ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
|
25
|
+
EM::run do
|
26
|
+
linda = EM::RocketIO::Linda::Client.new ENV["LINDA_BASE"]
|
27
|
+
ts = linda.tuplespace[ENV["BABA"]]
|
28
|
+
|
29
|
+
def take_task_and_run(ts)
|
30
|
+
ts.take [:babascript, :eval] do |tuple|
|
31
|
+
loop do
|
32
|
+
print %Q{"#{tuple[2]}" #{tuple[3]} >}
|
33
|
+
line = STDIN.gets.strip
|
34
|
+
next if line.empty?
|
35
|
+
ts.write [:babascript, :return, tuple[4]["callback"], line]
|
36
|
+
break
|
37
|
+
end
|
38
|
+
take_task_and_run(ts)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
linda.io.on :connect do
|
43
|
+
puts "connect (#{linda.io.type}). You are now BABA."
|
44
|
+
take_task_and_run(ts)
|
45
|
+
end
|
46
|
+
end
|
data/lib/babascript/baba.rb
CHANGED
@@ -1,19 +1,39 @@
|
|
1
1
|
module BabaScript
|
2
2
|
def self.baba(&block)
|
3
|
-
self::Baba.run
|
3
|
+
self::Baba.run &block if block_given?
|
4
4
|
end
|
5
5
|
|
6
6
|
class Baba
|
7
|
-
|
8
|
-
|
7
|
+
|
8
|
+
def self.linda
|
9
|
+
@@linda ||= EM::RocketIO::Linda::Client.new BabaScript.LINDA_BASE
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.run(code=nil, &block)
|
13
|
+
raise ArgumentError "block or code require" unless block_given? or code.kind_of? String
|
14
|
+
EM::run do
|
15
|
+
linda.io.once :connect do
|
16
|
+
EM::defer do
|
17
|
+
if block_given?
|
18
|
+
::BabaScript::Baba.instance_eval &block
|
19
|
+
else
|
20
|
+
::BabaScript::Baba.instance_eval code
|
21
|
+
end
|
22
|
+
EM::add_timer 1 do
|
23
|
+
EM::stop
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
9
28
|
end
|
10
29
|
|
11
30
|
def self.method_missing(name, *args)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
31
|
+
cid = __create_callback_id
|
32
|
+
tuple = [:babascript, :eval, name, args, {:callback => cid}]
|
33
|
+
ts = linda.tuplespace[BabaScript.LINDA_SPACE]
|
34
|
+
ts.write tuple
|
35
|
+
result = ts.take [:babascript, :return, cid]
|
36
|
+
return result[3]
|
17
37
|
end
|
18
38
|
|
19
39
|
private
|
data/lib/babascript/version.rb
CHANGED
data/lib/babascript.rb
CHANGED
data/samples/sample.bb
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
#!/usr/bin/env baba
|
2
|
+
# -*- coding: utf-8 -*-
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
res = かず助に行きたい人の出欠取ってください
|
5
|
+
puts res # => "6人です"
|
6
|
+
loop do
|
7
|
+
num = res.to_i
|
8
|
+
if num > 0
|
9
|
+
puts では予約してください("#{num}人")
|
10
|
+
exit
|
11
|
+
else
|
12
|
+
res = 残念・・その次の週はどうですか?
|
13
|
+
puts res
|
14
|
+
end
|
7
15
|
end
|
8
|
-
|
data/samples/sample.rb
CHANGED
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: babascript
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sho Hashimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: em-rocketio-linda-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - '>='
|
@@ -85,6 +85,7 @@ email:
|
|
85
85
|
- hashimoto@shokai.org
|
86
86
|
executables:
|
87
87
|
- baba
|
88
|
+
- baba-vm
|
88
89
|
extensions: []
|
89
90
|
extra_rdoc_files: []
|
90
91
|
files:
|
@@ -96,6 +97,7 @@ files:
|
|
96
97
|
- Rakefile
|
97
98
|
- babascript.gemspec
|
98
99
|
- bin/baba
|
100
|
+
- bin/baba-vm
|
99
101
|
- lib/babascript.rb
|
100
102
|
- lib/babascript/baba.rb
|
101
103
|
- lib/babascript/version.rb
|
@@ -127,4 +129,3 @@ signing_key:
|
|
127
129
|
specification_version: 4
|
128
130
|
summary: BabaScript is a script launguage which runs on @takumibaba
|
129
131
|
test_files: []
|
130
|
-
has_rdoc:
|