class
Lua::Stack
- Lua::Stack
- Reference
- Object
Included Modules
- Lua::StackMixin::Chunk
- Lua::StackMixin::ClassSupport
- Lua::StackMixin::CoroutineSupport
- Lua::StackMixin::ErrorHandling
- Lua::StackMixin::Registry
- Lua::StackMixin::StandardLibraries
- Lua::StackMixin::TableSupport
- Lua::StackMixin::Type
- Lua::StackMixin::Util
Defined in:
lua/stack.crConstructors
-
.new(state : LibLua::State, libs)
Initializes new Lua stack running in an existed state.
-
.new(libs = :all)
Initializes new Lua stack running in a new, independent state.
Instance Method Summary
-
#<<(o)
Adds Crystal object to Lua stack.
-
#[](pos : Int)
Fetches value from the stack.
-
#close
Destroys all objects in the given Lua state.
- #closed? : Bool
- #libs : Set(Symbol)
-
#pop
Removes element from the top of the stack and returns it.
-
#remove(n : Int = 1)
Removes n elements from the stack.
-
#size : Int
Returns the index of the top element in the stack.
- #state : LibLua::State
-
#to_s(io : IO)
Represents the stack as a string.
-
#top
Returns the top element and does not remove it from the stack.
Instance methods inherited from module Lua::StackMixin::ClassSupport
pushclosure(proc : Proc)
pushclosure,
pushmetatable(type : LuaCallable.class)
pushmetatable,
pushobject(a : LuaCallable)
pushobject
Instance methods inherited from module Lua::StackMixin::StandardLibraries
open_libs(libraries)
open_libs
Macros inherited from module Lua::StackMixin::StandardLibraries
open_library(library)
open_library
Instance methods inherited from module Lua::StackMixin::CoroutineSupport
newthread(f : Function)
newthread,
status
status
Instance methods inherited from module Lua::StackMixin::TableSupport
pushtable(a : Array)pushtable(a : Hash) pushtable
Instance methods inherited from module Lua::StackMixin::Registry
rawgeti(ref)
rawgeti,
reference(pos)
reference,
unref(ref)
unref
Instance methods inherited from module Lua::StackMixin::Chunk
run(buff : String, name : String | Nil = nil)run(lua_file : File) run
Instance methods inherited from module Lua::StackMixin::Util
get_global(name : String)
get_global,
getinfo(what)
getinfo,
set_global(name : String, value)
set_global,
version
version
Instance methods inherited from module Lua::StackMixin::Type
crystal_base_type_at(pos : Int)
crystal_base_type_at,
crystal_type_at(pos : Int)
crystal_type_at,
crystal_type_info_at(pos : Int)
crystal_type_info_at,
type_at(pos : Int)
type_at,
typename(pos : Int)typename(type : TYPE) typename
Constructor Detail
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 Method Detail
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