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-1.0.15 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.0.14 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.0.13 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.0.12 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.0.11 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.0.10 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.0.9 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.0.8 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.0.7 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.0.6 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.0.5 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.0.4 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.0.3 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.0.2 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.0.1 lib/immunio/rufus_lua_ext/ref.rb
immunio-1.0.0 lib/immunio/rufus_lua_ext/ref.rb
immunio-0.16.1 lib/immunio/rufus_lua_ext/ref.rb
immunio-0.16.0 lib/immunio/rufus_lua_ext/ref.rb