to_lua 0.0.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.
- checksums.yaml +7 -0
- data/lib/to_lua/extensions.rb +51 -0
- data/lib/to_lua/helpers.rb +37 -0
- data/lib/to_lua.rb +29 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 788d72b7334d20049dc49d469132b848617c9307
|
4
|
+
data.tar.gz: f865e91cb845f1ca85fc0fab501f495aa1011977
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3b22748559a85c9f2e77a58cf041c68ae87da6efc7f5cdbd6a343daa5ada514f7b49763e668dfe2c79157505bcb43f10461883a30c4433caaa69c2f3276d0a3a
|
7
|
+
data.tar.gz: 5baf0f0e092430b092dbdb27a076d2ddd121b85ff731972dda6f58f858713ceaa36044c90c86b67b83d6d50aa744c221e28c4fab89cd0c2f5105450e8444ea07
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require_relative 'helpers'
|
2
|
+
|
3
|
+
module ToLua
|
4
|
+
module Extensions
|
5
|
+
module Hash
|
6
|
+
def to_lua
|
7
|
+
fields = []
|
8
|
+
|
9
|
+
self.each do |key, value|
|
10
|
+
field = '['
|
11
|
+
field << key.to_s.to_lua
|
12
|
+
field << ']='
|
13
|
+
field << value.to_lua
|
14
|
+
fields << field
|
15
|
+
end
|
16
|
+
|
17
|
+
'{' + fields.join(',') + '}'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module Array
|
22
|
+
def to_lua
|
23
|
+
fields = []
|
24
|
+
|
25
|
+
self.each do |value|
|
26
|
+
fields << value.to_lua
|
27
|
+
end
|
28
|
+
|
29
|
+
'{' + fields.join(',') + '}'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module String
|
34
|
+
def to_lua
|
35
|
+
'"' + ToLua::Helpers.encode_string(self) + '"'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module NilClass
|
40
|
+
def to_lua
|
41
|
+
'nil'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module ToString
|
46
|
+
def to_lua
|
47
|
+
self.to_s
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ToLua
|
2
|
+
class Helpers
|
3
|
+
LUA_C_STYLE_ESCAPES = {
|
4
|
+
"\a" => "\\a",
|
5
|
+
"\b" => "\\b",
|
6
|
+
"\f" => "\\f",
|
7
|
+
"\n" => "\\n",
|
8
|
+
"\r" => "\\r",
|
9
|
+
"\t" => "\\t",
|
10
|
+
"\v" => "\\v",
|
11
|
+
"\\" => "\\\\",
|
12
|
+
"\"" => "\\\"",
|
13
|
+
"'" => "\\'",
|
14
|
+
"[" => "\\[",
|
15
|
+
"]" => "\\]"
|
16
|
+
}.freeze
|
17
|
+
|
18
|
+
def self.encode_string(string)
|
19
|
+
encoded = []
|
20
|
+
|
21
|
+
string.each_char do |char|
|
22
|
+
if LUA_C_STYLE_ESCAPES[char]
|
23
|
+
encoded << LUA_C_STYLE_ESCAPES[char]
|
24
|
+
elsif char =~ /^[^[:print:]]$/
|
25
|
+
char.each_byte do |byte|
|
26
|
+
encoded << '\\'
|
27
|
+
encoded << byte.to_s
|
28
|
+
end
|
29
|
+
else
|
30
|
+
encoded << char
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
encoded.join
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/to_lua.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'to_lua/extensions'
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
include ToLua::Extensions::Hash
|
5
|
+
end
|
6
|
+
|
7
|
+
class Array
|
8
|
+
include ToLua::Extensions::Array
|
9
|
+
end
|
10
|
+
|
11
|
+
class String
|
12
|
+
include ToLua::Extensions::String
|
13
|
+
end
|
14
|
+
|
15
|
+
class NilClass
|
16
|
+
include ToLua::Extensions::NilClass
|
17
|
+
end
|
18
|
+
|
19
|
+
class Numeric
|
20
|
+
include ToLua::Extensions::ToString
|
21
|
+
end
|
22
|
+
|
23
|
+
class TrueClass
|
24
|
+
include ToLua::Extensions::ToString
|
25
|
+
end
|
26
|
+
|
27
|
+
class FalseClass
|
28
|
+
include ToLua::Extensions::ToString
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: to_lua
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mantas Norvaiša
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-14 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: mntnorv@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/to_lua.rb
|
20
|
+
- lib/to_lua/extensions.rb
|
21
|
+
- lib/to_lua/helpers.rb
|
22
|
+
homepage: https://github.com/mntnorv/to_lua
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.4.1
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Serialize objects to lua tables
|
46
|
+
test_files: []
|