56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/to_lua/generator.rb', line 56
def to_lua(state = nil)
state = State.from_state(state)
depth = state.depth += 1
fields = []
self.each do |key, value|
field = ''
field << state.indent * state.depth if state.pretty?
key_str = key.to_s
if Helpers.valid_identifier?(key_str)
field << key_str
else
field << '['
field << key_str.to_lua
field << ']'
end
field << ' ' if state.pretty?
field << '='
field << ' ' if state.pretty?
field << value.to_lua(state)
fields << field
end
depth = state.depth -= 1
join_str = state.pretty? ? ",\n" : ','
result = '{'
result << "\n" if state.pretty?
result << fields.join(join_str)
result << "\n" if state.pretty?
result << state.indent * depth if state.pretty?
result << '}'
result
end
|