Class: Rufus::Lua::Ref

Inherits:
Object
  • Object
show all
Includes:
StateMixin
Defined in:
lib/rufus/lua/objects.rb

Overview

The parent class for Table, Function and Coroutine. Simply holds a reference to the object in the Lua registry.

Direct Known Subclasses

Coroutine, Function, Table

Constant Summary

Constants included from StateMixin

StateMixin::LUA_ENVIRONINDEX, StateMixin::LUA_GLOBALSINDEX, StateMixin::LUA_MULTRET, StateMixin::LUA_NOREF, StateMixin::LUA_REFNIL, StateMixin::LUA_REGISTRYINDEX, StateMixin::TBOOLEAN, StateMixin::TFUNCTION, StateMixin::TLIGHTUSERDATA, StateMixin::TNIL, StateMixin::TNONE, StateMixin::TNUMBER, StateMixin::TSTRING, StateMixin::TTABLE, StateMixin::TTHREAD, StateMixin::TUSERDATA

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointer) ⇒ Ref

Returns a new instance of Ref.



41
42
43
44
# File 'lib/rufus/lua/objects.rb', line 41

def initialize (pointer)
  @pointer = pointer
  @ref = Lib.luaL_ref(@pointer, LUA_REGISTRYINDEX)
end

Instance Attribute Details

#refObject (readonly)

The reference in the Lua registry. (You shouldn’t care about this value)



39
40
41
# File 'lib/rufus/lua/objects.rb', line 39

def ref
  @ref
end

Instance Method Details

#freeObject

Frees the reference to this object (Problably a good idea if you want Lua’s GC to get rid of it later).



50
51
52
53
# File 'lib/rufus/lua/objects.rb', line 50

def free
  Lib.luaL_unref(@pointer, LUA_REGISTRYINDEX, @ref)
  @ref = nil
end