Lua::Stack
Inherits Lua::StackMixin::FunctionSupport / Lua::StackMixin::ClassSupport / Lua::StackMixin::StandardLibraries / Lua::StackMixin::CoroutineSupport / Lua::StackMixin::ErrorHandling / Lua::StackMixin::TableSupport / Lua::StackMixin::Registry / Lua::StackMixin::Chunk / Lua::StackMixin::Util / Lua::StackMixin::Type / Reference / Object
Constructors
Initializes new Lua stack running in an existed state. Has to be closed to call the corresponding garbage-collection metamethods on Lua side.
Initializes new Lua stack running in a new, independent state. Has to be closed to call the corresponding garbage-collection metamethods on Lua side.
By default it loads all standard libraries. But that's possible to
load only a subset of them using libs named parameter. If you
pass nil as libs parameter, none of standard libraries will be loaded.
stack = Lua::Stack.new
# ...
stack.close
Instance methods
Adds Crystal object to Lua stack.
Lua::Stack.new.tap do |stack|
stack << 10
stack << "str"
stack << false
end
Fetches value from the stack.
stack = Lua::Stack.new
stack << 10.01
stack << "lua"
stack[1] # => 10.01
stack[2] # => "lua"
Removes element from the top of the stack and returns it.
stack = Lua::Stack.new
stack << 10.01
stack.size # => 1
stack.pop # => 10.01
stack.size # => 0
Removes n elements from the stack.
stack = Lua::Stak.new
stack << "a"
stack << "b"
stack << "c"
stack.remove(2) # => nil
stack.size # => 1
Returns the index of the top element in the stack. Because indices start at 1, this result is equal to the number of elements in the stack; in particular, 0 means an empty stack.
stack = Lua::Stack.new
stack.size # => 0
stack << 10
stack.size # => 1
Represents the stack as a string.
stack = Lua::Stack.new.tap do |s|
s << 42.24
s << false
s << "hello!"
end
stack.to_s # =>
# 3 : TSTRING(string) hello!
# 2 : TBOOLEAN(boolean) false
# 1 : TNUMBER(number) 42.24
Returns the top element and does not remove it from the stack.
stack = Lua::Stack.new
stack << "hey"
stack.top # => "hey"
stack.size # => 0