to_lua 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: 31e8b653f5ac0333ede2653b5af9447c662df320
4
- data.tar.gz: 1f955a8a284beacd93c259cb2c8e80adbbf2706d
3
+ metadata.gz: 62072c4e042598c081315d2b4a8205f5f5e27cdd
4
+ data.tar.gz: 09482878204c938bd03716697b8cefcaeb45491b
5
5
  SHA512:
6
- metadata.gz: c7be685b845f2642d6d38a314616284eda6900c0fdad020d6540078d0a34b863f6557cfa7a39b3bc8242043da54e4fff7edb3b6d8e7f296361039aeabae3a0e4
7
- data.tar.gz: fb55dc6159ad78a4c8f6a7ded9b5029d39ca7305744e31f1d3d1049c5a586143aa7955031117be68f1d4ca8a351aab5a6167f0a03686a68a9e7cc928e7b4a210
6
+ metadata.gz: d739faa3ee8539b53f42bb9710cf8eea5a217e8307d9bbacb03734dc9a3644a15e46b3414fb79aa11736fae8ce2e8ff01648d5f5d54120e1f246fb65289f8dba
7
+ data.tar.gz: dd48b005f845439ff4bc086fc38cbc0597091eea6ef9dbb66fe54be992f6f12e59f9f813a02fbb9e738800925165fbc73b481439386ce67ba7d97a8446a5543c
@@ -62,9 +62,16 @@ module ToLua
62
62
  self.each do |key, value|
63
63
  field = ''
64
64
  field << state.indent * state.depth if state.pretty?
65
- field << '['
66
- field << key.to_s.to_lua
67
- field << ']'
65
+
66
+ key_str = key.to_s
67
+ if Helpers.valid_identifier?(key_str)
68
+ field << key_str
69
+ else
70
+ field << '['
71
+ field << key_str.to_lua
72
+ field << ']'
73
+ end
74
+
68
75
  field << ' ' if state.pretty?
69
76
  field << '='
70
77
  field << ' ' if state.pretty?
@@ -14,6 +14,11 @@ module ToLua
14
14
  "[" => "\\[",
15
15
  "]" => "\\]"
16
16
  }.freeze
17
+
18
+ LUA_RESERVED_KEYWORDS = %w(
19
+ and break do else elseif end false for function if in local nil not or
20
+ repeat return then true until while
21
+ )
17
22
 
18
23
  def self.encode_string(string)
19
24
  encoded = []
@@ -33,5 +38,17 @@ module ToLua
33
38
 
34
39
  encoded.join
35
40
  end
41
+
42
+ def self.valid_identifier?(identifier)
43
+ valid_identifier_characters?(identifier) && !reserved_keyword?(identifier)
44
+ end
45
+
46
+ def self.valid_identifier_characters?(identifier)
47
+ !!(identifier =~ /^[_a-zA-Z][_a-zA-Z0-9]*$/)
48
+ end
49
+
50
+ def self.reserved_keyword?(identifier)
51
+ LUA_RESERVED_KEYWORDS.include?(identifier)
52
+ end
36
53
  end
37
54
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_lua
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
  - Mantas Norvaiša
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-14 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2015-05-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.2.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.2.0
13
41
  description:
14
42
  email: mntnorv@gmail.com
15
43
  executables: []
@@ -31,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
31
59
  requirements:
32
60
  - - ">="
33
61
  - !ruby/object:Gem::Version
34
- version: '0'
62
+ version: 2.0.0
35
63
  required_rubygems_version: !ruby/object:Gem::Requirement
36
64
  requirements:
37
65
  - - ">="
@@ -39,9 +67,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
39
67
  version: '0'
40
68
  requirements: []
41
69
  rubyforge_project:
42
- rubygems_version: 2.4.5
70
+ rubygems_version: 2.4.6
43
71
  signing_key:
44
72
  specification_version: 4
45
- summary: Serialize objects to lua tables
73
+ summary: Serialize Ruby objects to lua tables
46
74
  test_files: []
47
- has_rdoc: