Module: Rufus::Lua
- Defined in:
- lib/rufus/lua/lib.rb,
lib/rufus/lua/state.rb,
lib/rufus/lua/utils.rb,
lib/rufus/lua/objects.rb
Defined Under Namespace
Modules: Lib, StateMixin Classes: Coroutine, Function, LuaError, Ref, State, Table
Class Method Summary collapse
-
.to_lua_s(o) ⇒ Object
Turns a Ruby instance into a Lua parseable string representation.
-
.to_lua_table_s(o) ⇒ Object
Turns a Ruby Array or Hash instance into a Lua parseable string representation.
Class Method Details
.to_lua_s(o) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rufus/lua/utils.rb', line 43 def self.to_lua_s (o) case o when String then o.inspect when Fixnum then o.to_s when Float then o.to_s when TrueClass then o.to_s when FalseClass then o.to_s when Hash then to_lua_table_s(o) when Array then to_lua_table_s(o) else raise( ArgumentError.new( "don't how to turning into a Lua string representation "+ "Ruby instances of class '#{o.class}'")) end end |
.to_lua_table_s(o) ⇒ Object
Turns a Ruby Array or Hash instance into a Lua parseable string representation.
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rufus/lua/utils.rb', line 67 def self.to_lua_table_s (o) s = if o.is_a?(Array) o.collect { |e| to_lua_s(e) } else o.collect { |k, v| "#{to_lua_s(k)}: #{to_lua_s(v)}" } end "{ #{s.join(', ')} }" end |