Sha256: 40267b5f7f379f65de80eb8da79f3a2b21778e4ca45ec0234d95c3c756098800

Contents?: true

Size: 639 Bytes

Versions: 38

Compression:

Stored size: 639 Bytes

Contents

module Rufus::Lua
  # Auto-unref Lua ref when it goes out of scope in Ruby.
  class Ref
    def initialize_with_finalizer(*args)
      initialize_without_finalizer(*args)

      ObjectSpace.define_finalizer self, self.class.finalize(@pointer, @ref)
    end
    alias_method :initialize_without_finalizer, :initialize
    alias_method :initialize, :initialize_with_finalizer

    def self.finalize(pointer, ref)
      proc do
        Lib.luaL_unref(pointer, LUA_REGISTRYINDEX, ref)
      end
    end

    undef :free
    def free
      # Noop. Taken care of by finalizer. Should not conflict.
    end

    public :load_onto_stack
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
immunio-2.0.4 lib/immunio/rufus_lua_ext/ref.rb
immunio-2.0.3 lib/immunio/rufus_lua_ext/ref.rb
immunio-2.0.2 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.2.1 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.1.19 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.1.18 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.1.16 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.1.15 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.1.13 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.1.11 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.1.10 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.1.7 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.1.6 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.1.5 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.1.2 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.1.1 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.1.0 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.0.22 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.0.19 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.0.17 lib/immunio/rufus_lua_ext/ref.rb