lomic 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +1 -1
- data/Rakefile +2 -0
- data/VERSION.yml +2 -2
- data/bin/lomic +27 -0
- data/examples/listen_path.rb +15 -0
- data/examples/nomic_initial_rules.rb +2 -2
- data/examples/priority.rb +1 -1
- data/examples/simple.rb +1 -1
- data/lib/lomic.rb +28 -0
- data/lib/lomic/EventEngine.rb +16 -2
- data/lib/lomic/GameState.rb +2 -2
- data/lib/lomic/{Lomic.rb → LomicBase.rb} +8 -5
- data/lib/lomic/LomicParser.rb +8 -2
- data/lib/lomic/Rule.rb +1 -1
- metadata +45 -10
- data/lib/Lomic.rb +0 -16
data/Manifest
CHANGED
data/Rakefile
CHANGED
@@ -10,7 +10,9 @@ begin
|
|
10
10
|
gem.email = "gilbertbgarza@gmail.com"
|
11
11
|
gem.homepage = "http://github.com/mindeavor/lomic"
|
12
12
|
gem.authors = ["Gilbert B Garza"]
|
13
|
+
gem.add_development_dependency "commander", ">= 4.0.3"
|
13
14
|
gem.add_development_dependency "cucumber", ">= 0.8.0"
|
15
|
+
gem.add_development_dependency "json", ">= 1.4.3"
|
14
16
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
17
|
end
|
16
18
|
Jeweler::GemcutterTasks.new
|
data/VERSION.yml
CHANGED
data/bin/lomic
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'commander/import'
|
3
|
+
require 'jeweler'
|
4
|
+
# $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
5
|
+
dir = File.join(File.dirname(__FILE__), '..')
|
6
|
+
|
7
|
+
program :version, Jeweler::VersionHelper.new(dir).to_s
|
8
|
+
program :description, 'Starts up an instance of lomic'
|
9
|
+
|
10
|
+
global_option '--verbose'
|
11
|
+
|
12
|
+
command :start do |c|
|
13
|
+
c.syntax = 'lomic start <address:port> <rule file>'
|
14
|
+
c.description = 'Starts an instance of lomic that listens to <address:port> and populates its rules with <rule file>.'
|
15
|
+
c.action do |args,options|
|
16
|
+
address,rfilename = args
|
17
|
+
ip,port = address.split(':')
|
18
|
+
# TODO: fancy error checking
|
19
|
+
require 'socket'
|
20
|
+
require 'lomic'
|
21
|
+
socket = TCPSocket::open(ip,port)
|
22
|
+
puts "\nLomic started, listening for first event on: #{args.inspect}"
|
23
|
+
Lomic.verbose = options.verbose
|
24
|
+
Lomic.new_game(socket,rfilename)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -1,9 +1,9 @@
|
|
1
|
-
class Player <
|
1
|
+
class Player < LomicBase
|
2
2
|
var :number
|
3
3
|
end
|
4
4
|
|
5
5
|
# global data: all lomic functions search exclusively in this class for global variables
|
6
|
-
class Globals <
|
6
|
+
class Globals < LomicBase
|
7
7
|
var :currentRule # Rule is a built-in class type
|
8
8
|
var :ruleChangeType => ""
|
9
9
|
|
data/examples/priority.rb
CHANGED
data/examples/simple.rb
CHANGED
data/lib/lomic.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
$:.push File.expand_path(File.dirname(__FILE__) + '/lib')
|
2
|
+
require 'lomic/Event'
|
3
|
+
require 'lomic/EventEngine'
|
4
|
+
require 'lomic/GameState'
|
5
|
+
require 'lomic/LomicBase'
|
6
|
+
require 'lomic/Rule'
|
7
|
+
require 'lomic/LomicParser'
|
8
|
+
|
9
|
+
module Lomic
|
10
|
+
@@verbose = false
|
11
|
+
require 'json'
|
12
|
+
|
13
|
+
def self.new_game(socket,filename)
|
14
|
+
gstate = LomicParser.load_source(filename)
|
15
|
+
puts 'Waiting for response from server...'
|
16
|
+
first_event = socket.gets.strip!
|
17
|
+
puts "Received first event: #{first_event}" if verbose?
|
18
|
+
gstate.run(first_event,socket)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.verbose?
|
22
|
+
@@verbose
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.verbose=(new_val)
|
26
|
+
@@verbose = new_val
|
27
|
+
end
|
28
|
+
end
|
data/lib/lomic/EventEngine.rb
CHANGED
@@ -7,10 +7,11 @@ class EventEngine
|
|
7
7
|
@counter = 0 # the number of event code blocks executed
|
8
8
|
end
|
9
9
|
|
10
|
-
def run(event_name, rules)
|
10
|
+
def run(event_name, rules, socket)
|
11
|
+
@socket = socket
|
11
12
|
add_sort_events rules
|
12
13
|
@next_event = event_name
|
13
|
-
|
14
|
+
|
14
15
|
begin
|
15
16
|
event_name = @next_event
|
16
17
|
@next_event = nil
|
@@ -21,6 +22,19 @@ class EventEngine
|
|
21
22
|
end while @next_event.nil? == false
|
22
23
|
end
|
23
24
|
|
25
|
+
def listen(*valid_events)
|
26
|
+
puts "Listening for valid events: #{valid_events.inspect}" if Lomic.verbose?
|
27
|
+
res = @socket.gets.strip!
|
28
|
+
if not valid_events.include? res
|
29
|
+
result = {:status => 'fail', :reason => 'invalid event'}.to_json
|
30
|
+
@socket.puts result
|
31
|
+
else
|
32
|
+
result = {:status => 'ok'}.to_json
|
33
|
+
@socket.puts result
|
34
|
+
end
|
35
|
+
set_next res
|
36
|
+
end
|
37
|
+
|
24
38
|
def set_next(event_name)
|
25
39
|
@next_event = event_name
|
26
40
|
end
|
data/lib/lomic/GameState.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
module Lomic
|
2
2
|
|
3
3
|
### This class helps clean up in-game class definitions
|
4
|
-
class
|
4
|
+
class LomicBase
|
5
5
|
class << self
|
6
6
|
public :define_method, :remove_method
|
7
|
+
public :class_variable_get
|
7
8
|
end
|
8
9
|
|
9
10
|
def self.var(symbols)
|
@@ -81,10 +82,12 @@ class Lomic
|
|
81
82
|
|
82
83
|
def initialize
|
83
84
|
@init_used = {}
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
if self.class.class_variable_defined? "@@__#{className}_inits__"
|
86
|
+
inits = self.class.class_variable_get "@@__#{className}_inits__"
|
87
|
+
inits.each do |var,val|
|
88
|
+
instance_variable_set "@#{var}", val
|
89
|
+
@init_used[var] = true
|
90
|
+
end
|
88
91
|
end
|
89
92
|
end
|
90
93
|
|
data/lib/lomic/LomicParser.rb
CHANGED
@@ -14,7 +14,14 @@ class LomicParser
|
|
14
14
|
# TODO: ensure number is int
|
15
15
|
@currentRule = Rule.new(number)
|
16
16
|
if @first_rule
|
17
|
-
|
17
|
+
begin
|
18
|
+
@state.globals = instance_eval 'Globals.new'
|
19
|
+
rescue
|
20
|
+
# No Globals class was declared. Create one
|
21
|
+
instance_eval "class Globals < LomicBase
|
22
|
+
end"
|
23
|
+
@state.globals = instance_eval 'Globals.new'
|
24
|
+
end
|
18
25
|
@first_rule = false
|
19
26
|
end
|
20
27
|
|
@@ -35,7 +42,6 @@ class LomicParser
|
|
35
42
|
def self.load_source(filename)
|
36
43
|
dsl = new
|
37
44
|
dsl.instance_eval(File.read(filename),filename)
|
38
|
-
# dsl.gamestate.globals = (dsl.instance_eval 'Globals.new')
|
39
45
|
dsl.gamestate
|
40
46
|
end
|
41
47
|
end
|
data/lib/lomic/Rule.rb
CHANGED
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.2
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gilbert B Garza
|
@@ -15,13 +15,29 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
19
|
-
default_executable:
|
18
|
+
date: 2010-06-15 00:00:00 -05:00
|
19
|
+
default_executable: lomic
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: commander
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 57
|
30
|
+
segments:
|
31
|
+
- 4
|
32
|
+
- 0
|
33
|
+
- 3
|
34
|
+
version: 4.0.3
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: cucumber
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
25
41
|
none: false
|
26
42
|
requirements:
|
27
43
|
- - ">="
|
@@ -33,11 +49,27 @@ dependencies:
|
|
33
49
|
- 0
|
34
50
|
version: 0.8.0
|
35
51
|
type: :development
|
36
|
-
version_requirements: *
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: json
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 1
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 4
|
65
|
+
- 3
|
66
|
+
version: 1.4.3
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
37
69
|
description: Lomic is a Domain Specific Language (DSL) intended to be used for Pomic, a programming version of the game Nomic.
|
38
70
|
email: gilbertbgarza@gmail.com
|
39
|
-
executables:
|
40
|
-
|
71
|
+
executables:
|
72
|
+
- lomic
|
41
73
|
extensions: []
|
42
74
|
|
43
75
|
extra_rdoc_files:
|
@@ -51,6 +83,7 @@ files:
|
|
51
83
|
- Rakefile
|
52
84
|
- TODO
|
53
85
|
- VERSION.yml
|
86
|
+
- examples/listen_path.rb
|
54
87
|
- examples/nomic_initial_rules.rb
|
55
88
|
- examples/priority.rb
|
56
89
|
- examples/simple.rb
|
@@ -58,13 +91,14 @@ files:
|
|
58
91
|
- features/step_definitions/steps.rb
|
59
92
|
- features/support/env.rb
|
60
93
|
- features/var_init.feature
|
61
|
-
- lib/
|
94
|
+
- lib/lomic.rb
|
62
95
|
- lib/lomic/Event.rb
|
63
96
|
- lib/lomic/EventEngine.rb
|
64
97
|
- lib/lomic/GameState.rb
|
65
|
-
- lib/lomic/
|
98
|
+
- lib/lomic/LomicBase.rb
|
66
99
|
- lib/lomic/LomicParser.rb
|
67
100
|
- lib/lomic/Rule.rb
|
101
|
+
- bin/lomic
|
68
102
|
has_rdoc: true
|
69
103
|
homepage: http://github.com/mindeavor/lomic
|
70
104
|
licenses: []
|
@@ -100,6 +134,7 @@ signing_key:
|
|
100
134
|
specification_version: 3
|
101
135
|
summary: A Ruby DSL for the game Nomic
|
102
136
|
test_files:
|
137
|
+
- examples/listen_path.rb
|
103
138
|
- examples/nomic_initial_rules.rb
|
104
139
|
- examples/priority.rb
|
105
140
|
- examples/simple.rb
|
data/lib/Lomic.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
$:.push File.expand_path(File.dirname(__FILE__) + '/lib')
|
2
|
-
require 'lomic/Event'
|
3
|
-
require 'lomic/EventEngine'
|
4
|
-
require 'lomic/GameState'
|
5
|
-
require 'lomic/Lomic'
|
6
|
-
require 'lomic/Rule'
|
7
|
-
require 'lomic/LomicParser'
|
8
|
-
|
9
|
-
module Lomic
|
10
|
-
VERSION = '0.0.1'
|
11
|
-
|
12
|
-
def self.parse(filename, start_event="game:start")
|
13
|
-
gstate = LomicParser.load_source(filename)
|
14
|
-
gstate.emit start_event
|
15
|
-
end
|
16
|
-
end
|