transparent-lua 0.6.1 → 0.7.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 +8 -8
- data/features/special_methods.feature +8 -0
- data/lib/transparent_lua.rb +22 -6
- data/lib/transparent_lua/version.rb +1 -1
- metadata +4 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,15 +1,15 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            !binary "U0hBMQ==":
         | 
| 3 3 | 
             
              metadata.gz: !binary |-
         | 
| 4 | 
            -
                 | 
| 4 | 
            +
                NGNlNTJiOTIyOWQ0NzAxNjA1ZDEyNmEwZWRhMzg2NDM0NjhmZmNjNQ==
         | 
| 5 5 | 
             
              data.tar.gz: !binary |-
         | 
| 6 | 
            -
                 | 
| 6 | 
            +
                NWNjYWU2N2VmYThhNWJiOWEwNDQxZDZmNzVlZWYwZDZmOTJkYTYyZQ==
         | 
| 7 7 | 
             
            SHA512:
         | 
| 8 8 | 
             
              metadata.gz: !binary |-
         | 
| 9 | 
            -
                 | 
| 10 | 
            -
                 | 
| 11 | 
            -
                 | 
| 9 | 
            +
                NjY1Mzk0MDUxYzUwNDg0NTIyMzZhNzAyODVhZjZhZjFiZGQzMjRjYWUzOGNl
         | 
| 10 | 
            +
                MDhmNDEzODVlMTU3NTY4Zjg2OWU1NzQyNzFkNWNiMzAxODk2MjVlNmFjMzY2
         | 
| 11 | 
            +
                YWE5MjkwODZhNTJjMWQ4NWRkYzZmMWIyZWUyNDRkODIyNzVjZDQ=
         | 
| 12 12 | 
             
              data.tar.gz: !binary |-
         | 
| 13 | 
            -
                 | 
| 14 | 
            -
                 | 
| 15 | 
            -
                 | 
| 13 | 
            +
                MjQ0OWM5ZTJlMWUwZGYyYjlkODc0NTI3MWZjNzQyMWYxY2U1NzE1YzAxZWQ1
         | 
| 14 | 
            +
                NzI4NjFiYzQ0YmMzZGMxN2ViZWI5MTdiNjljYTliZGEzMjJhOWI4MjY4MzVl
         | 
| 15 | 
            +
                ODAwM2Q3YWM0ZWZhZTAwNTE1MmM2ZDMzOWQ0OGQ1ZjgzZTAzYzk=
         | 
| @@ -0,0 +1,8 @@ | |
| 1 | 
            +
            Feature: Special methods
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              Scenario: Calling a predicate method from Lua
         | 
| 4 | 
            +
                Given an empty sandbox
         | 
| 5 | 
            +
                And the following method definition as part of the sandbox: def test?; true; end;
         | 
| 6 | 
            +
                And the following line as Lua script: return(test_huh);
         | 
| 7 | 
            +
                When I execute the script
         | 
| 8 | 
            +
                Then it should return true
         | 
    
        data/lib/transparent_lua.rb
    CHANGED
    
    | @@ -15,7 +15,7 @@ class TransparentLua | |
| 15 15 | 
             
                  Array,
         | 
| 16 16 | 
             
              ]
         | 
| 17 17 |  | 
| 18 | 
            -
              attr_reader :sandbox, :state, :logger
         | 
| 18 | 
            +
              attr_reader :sandbox, :state, :logger, :predicate_method_suffix
         | 
| 19 19 |  | 
| 20 20 | 
             
              # @param [Object] sandbox The object which will be made visible to the lua script
         | 
| 21 21 | 
             
              # @param [Hash] options
         | 
| @@ -24,10 +24,11 @@ class TransparentLua | |
| 24 24 | 
             
              #   The sandbox must store the values itself or an error will be raised.
         | 
| 25 25 | 
             
              #   When false the locals are not reflected in the sandbox
         | 
| 26 26 | 
             
              def initialize(sandbox, options = {})
         | 
| 27 | 
            -
                @sandbox | 
| 28 | 
            -
                @state | 
| 29 | 
            -
                @logger | 
| 30 | 
            -
                 | 
| 27 | 
            +
                @sandbox                 = sandbox
         | 
| 28 | 
            +
                @state                   = options.fetch(:state) { Lua::State.new }
         | 
| 29 | 
            +
                @logger                  = options.fetch(:logger) { Logger.new('/dev/null') }
         | 
| 30 | 
            +
                @predicate_method_suffix = options.fetch(:predicate_method_suffix) { '_huh' }
         | 
| 31 | 
            +
                leak_locals              = options.fetch(:leak_globals) { false }
         | 
| 31 32 | 
             
                setup(leak_locals)
         | 
| 32 33 | 
             
              end
         | 
| 33 34 |  | 
| @@ -99,6 +100,7 @@ class TransparentLua | |
| 99 100 | 
             
              def index_table(object)
         | 
| 100 101 | 
             
                ->(t, k, *newindex_args) do
         | 
| 101 102 | 
             
                  method = get_method(object, k)
         | 
| 103 | 
            +
                  k = get_ruby_method_name(k)
         | 
| 102 104 | 
             
                  logger.debug { "Dispatching method #{method}(#{method.parameters})" }
         | 
| 103 105 |  | 
| 104 106 | 
             
                  case method
         | 
| @@ -113,8 +115,10 @@ class TransparentLua | |
| 113 115 | 
             
              end
         | 
| 114 116 |  | 
| 115 117 | 
             
              def get_method(object, method_name)
         | 
| 116 | 
            -
                 | 
| 118 | 
            +
                method_name = get_ruby_method_name(method_name)
         | 
| 117 119 | 
             
                object.method(method_name.to_sym)
         | 
| 120 | 
            +
              rescue NameError
         | 
| 121 | 
            +
                fail NoMethodError, "#{object}##{method_name.to_s} is not a method (but might be a valid message which is not supported)"
         | 
| 118 122 | 
             
              end
         | 
| 119 123 |  | 
| 120 124 | 
             
              # @param [Method] method
         | 
| @@ -156,4 +160,16 @@ class TransparentLua | |
| 156 160 | 
             
              rescue NoMethodError
         | 
| 157 161 | 
             
                false
         | 
| 158 162 | 
             
              end
         | 
| 163 | 
            +
             | 
| 164 | 
            +
              # @param [Symbol] lua_method_name
         | 
| 165 | 
            +
              # @return [Symbol] ruby method name
         | 
| 166 | 
            +
              def get_ruby_method_name(lua_method_name)
         | 
| 167 | 
            +
                lua_method_name = String(lua_method_name)
         | 
| 168 | 
            +
                case lua_method_name
         | 
| 169 | 
            +
                when /#{predicate_method_suffix}$/
         | 
| 170 | 
            +
                  return lua_method_name.gsub(/#{predicate_method_suffix}$/, '?').to_sym
         | 
| 171 | 
            +
                else
         | 
| 172 | 
            +
                  return lua_method_name.to_sym
         | 
| 173 | 
            +
                end
         | 
| 174 | 
            +
              end
         | 
| 159 175 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: transparent-lua
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.7.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Christian Haase
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015- | 
| 11 | 
            +
            date: 2015-09-21 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rlua
         | 
| @@ -81,6 +81,7 @@ files: | |
| 81 81 | 
             
            - Rakefile
         | 
| 82 82 | 
             
            - features/env.rb
         | 
| 83 83 | 
             
            - features/sandbox_exposition.feature
         | 
| 84 | 
            +
            - features/special_methods.feature
         | 
| 84 85 | 
             
            - features/step_definitions/preparation_steps.rb
         | 
| 85 86 | 
             
            - features/step_definitions/transparent_lua_steps.rb
         | 
| 86 87 | 
             
            - features/step_definitions/validation_steps.rb
         | 
| @@ -117,6 +118,7 @@ summary: This library enables an easy way to pass complex objects between Ruby a | |
| 117 118 | 
             
            test_files:
         | 
| 118 119 | 
             
            - features/env.rb
         | 
| 119 120 | 
             
            - features/sandbox_exposition.feature
         | 
| 121 | 
            +
            - features/special_methods.feature
         | 
| 120 122 | 
             
            - features/step_definitions/preparation_steps.rb
         | 
| 121 123 | 
             
            - features/step_definitions/transparent_lua_steps.rb
         | 
| 122 124 | 
             
            - features/step_definitions/validation_steps.rb
         |