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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7dd87afb4cf770b6f702679cc5421e3b709d82a9
4
- data.tar.gz: 6d4202bd1400272d37811da54b38638fa33dbe80
3
+ metadata.gz: 1219669ef1f3883b038f307e2672c55f038e3e1d
4
+ data.tar.gz: 753b26e3e34eb229404aa9d178a5a682f621d282
5
5
  SHA512:
6
- metadata.gz: 103a60b1799186016cccb006c01a42656ea33343f81eabcf58b3b4f1b6ce6a0ebcda766ee17b8798809227547fc5951916af28c98ae57e8bb22d67a81ec0c3fd
7
- data.tar.gz: 9fa95cf3685919dd3ea07cd0872891f90afd76960f2135ac92fc62a65a7bd9884f444a68b4b1e56e6dc986e39e4234e1cce6b7ab639f82203a10aab2c3368977
6
+ metadata.gz: b8edcfde5f3db9fe504092c2257e3db3440e7be49d920420664ede6c1b0ad77e8d8c8b91e3bfee8313bfb9c7994c9f05cf61c6a1c647fef7d44b8f68a19314e1
7
+ data.tar.gz: 03c5474907ee1ea3a69df6234cfe72b3f08c6f0f3e70dcaad80c70622b35e8be73b85aed69fe447ff630b32742a8724a4350025fb40bfb9278500b150edcfcf3
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.2.0 2013-07-04
2
+
3
+ * get return value from Baba
4
+
1
5
  === 0.1.1 2013-06-22
2
6
 
3
7
  * --version option
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 "httparty"
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
@@ -32,7 +32,7 @@ if args.has_param? :e
32
32
  else
33
33
  args.argv.each do |fname|
34
34
  File.open(fname) do |f|
35
- BabaScript::Baba.instance_eval f.read
35
+ BabaScript::Baba.run f.read
36
36
  end
37
37
  end
38
38
  end
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
@@ -1,19 +1,39 @@
1
1
  module BabaScript
2
2
  def self.baba(&block)
3
- self::Baba.run(&block)
3
+ self::Baba.run &block if block_given?
4
4
  end
5
5
 
6
6
  class Baba
7
- def self.run(&block)
8
- self.instance_eval &block if block_given?
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
- tuple = [:babascript, :eval, name, args, {:callback => __create_callback_id}]
13
- query = {
14
- :body => {:tuple => tuple.to_json}
15
- }
16
- HTTParty.post("#{BabaScript.LINDA_BASE}/#{BabaScript.LINDA_SPACE}.write", query)
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
@@ -1,3 +1,3 @@
1
1
  module BabaScript
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/babascript.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "babascript/version"
2
2
  require "babascript/baba"
3
- require "httparty"
3
+ require "eventmachine"
4
+ require "em-rocketio-linda-client"
4
5
  require "json"
5
6
  require 'digest/md5'
6
7
 
data/samples/sample.bb CHANGED
@@ -1,8 +1,15 @@
1
1
  #!/usr/bin/env baba
2
+ # -*- coding: utf-8 -*-
2
3
 
3
- if 0 < Time.now.hour and Time.now.hour < 5
4
- もう寝よう!!
5
- else
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
@@ -6,8 +6,8 @@ require 'babascript'
6
6
 
7
7
  BabaScript.baba do
8
8
  if Time.now.hour < 12
9
- そろそろ起きたほうがいいのでは?
9
+ puts そろそろ起きたほうがいいのでは?
10
10
  else
11
- アイス買ってきてよ("#{rand(10)}本")
11
+ puts アイス買ってきてよ("#{rand(10)}本")
12
12
  end
13
13
  end
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.1.1
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-06-22 00:00:00.000000000 Z
11
+ date: 2013-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: httparty
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: