ReflectReference

ReflectReferences are simply references to date living either:

  • In a component
  • In a resource
  • In the allocator

Reflect references contain a standard interface which operates over the reflection layer exposed by Bevy and also provides a way to call various dynamic functions registered on the underlying pointed to data.

display_ref

Arguments:

ArgumentTypeDescription
sReflectReferenceThe reference to display

Returns:

ReturnDescription
StringThe reference in string format
print(ref:display_ref())
print(ref)

display_value

Arguments:

ArgumentTypeDescription
sReflectReferenceThe reference to display

Returns:

ReturnDescription
StringThe value in string format
print(ref:display_value())

get

The index function, allows you to index into the reflect reference.

Arguments:

ArgumentTypeDescription
keyScriptValueThe key to get the value for

Returns:

ReturnDescription
ScriptValueThe value
local value = ref:get(key)
-- same as
local value = ref.key
local value = ref[key]
local value = ref["key"]
-- for tuple structs
local valye = ref._1

set

Arguments:

ArgumentTypeDescription
keyScriptValueThe key to set the value for
valueScriptValueThe value to set

Returns:

ReturnDescription
ScriptValueThe result
ref:set(key, value)
-- same as
ref.key = value
ref[key] = value
ref["key"] = value
-- for tuple structs
ref._1 = value

push

Generic push method, if the underlying type supports it, will push the value into the end of the reference.

Arguments:

ArgumentTypeDescription
valueScriptValueThe value to push
ref:push(value)

pop

Generic pop method, if the underlying type supports it, will pop the value from the end of the reference.

Arguments:

ArgumentTypeDescription
sReflectReferenceThe reference to pop from

Returns:

ReturnDescription
ScriptValueThe popped value
local value = ref:pop()

insert

Generic insert method, if the underlying type supports it, will insert the value at the key.

Arguments:

ArgumentTypeDescription
keyScriptValueThe key to insert the value for
valueScriptValueThe value to insert
ref:insert(key, value)

clear

Generic clear method, if the underlying type supports it, will clear the referenced container type.

Arguments:

ArgumentTypeDescription
sReflectReferenceThe reference to clear
ref:clear()

len

Generic length method, if the underlying type supports it, will return the length of the referenced container or length relevant to the type itself (number of fields etc.).

Arguments:

ArgumentTypeDescription
sReflectReferenceThe reference to get the length of

Returns:

ReturnDescription
usizeThe length
length = ref:len()

remove

Generic remove method, if the underlying type supports it, will remove the value at the key.

Arguments:

ArgumentTypeDescription
keyScriptValueThe key to remove the value for

Returns:

ReturnDescription
ScriptValueThe removed value
local value = ref:remove(key)

iter

The iterator function, returns a function which can be called to iterate over the reference.

Arguments:

ArgumentTypeDescription
sReflectReferenceThe reference to iterate over

Returns:

ReturnDescription
ScriptFunctionMutThe iterator function
local iter = ref:iter()
local val = iter()
while val do
    print(val)
    next = iter()
end

-- same as 
for val in pairs(ref) do
    print(val)
end