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_GCCOLLECT, StateMixin::LUA_GCCOUNT, StateMixin::LUA_GCCOUNTB, StateMixin::LUA_GCRESTART, StateMixin::LUA_GCSETPAUSE, StateMixin::LUA_GCSETSTEPMUL, StateMixin::LUA_GCSTEP, StateMixin::LUA_GCSTOP, StateMixin::LUA_GLOBALSINDEX, StateMixin::LUA_MULTRET, StateMixin::LUA_NOREF, StateMixin::LUA_REFNIL, StateMixin::LUA_REGISTRYINDEX, StateMixin::SIMPLE_TYPES, 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.



16
17
18
19
20
21
22
# File 'lib/rufus/lua/objects.rb', line 16

def initialize(pointer)

  @pointer = pointer
  @ref = Lib.luaL_ref(@pointer, LUA_REGISTRYINDEX)
    # this pops the object out of the stack !
  @error_handler = 0
end

Instance Attribute Details

#refObject (readonly)

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



14
15
16
# File 'lib/rufus/lua/objects.rb', line 14

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).



27
28
29
30
31
# File 'lib/rufus/lua/objects.rb', line 27

def free

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