bevy_mod_scripting 0.24.0

Multi language scripting in Bevy
Documentation
local bms = import_namespace("bms")
local world = bms.world
local type = world.get_type_by_name("test_utils::test_data::SimpleEnum")

-- Struct Variant
local constructed = bms.construct(type, {
    variant = "Struct",
    foo = 123
})

assert(constructed:variant_name() == "Struct",
    "Value was constructed incorrectly, expected constructed.variant to be Struct but got " .. constructed:variant_name())
-- the fields of a variant are read off the enum value, which the declarations can't type
local foo = constructed.foo ---@diagnostic disable-line: undefined-field
assert(foo == 123,
    "Value was constructed incorrectly, expected constructed.foo to be 123 but got " .. tostring(foo))


-- TupleStruct Variant
local constructed = bms.construct(type, {
    variant = "TupleStruct",
    ["1"] = 123
})

assert(constructed:variant_name() == "TupleStruct",
    "Value was constructed incorrectly, expected constructed.variant to be TupleStruct but got " ..
    constructed:variant_name())
assert(constructed[1] == 123,
    "Value was constructed incorrectly, expected constructed._1 to be 123 but got " .. constructed[1])

-- Unit Variant
local constructed = bms.construct(type, {
    variant = "Unit"
})

assert(constructed:variant_name() == "Unit",
    "Value was constructed incorrectly, expected constructed.variant to be Unit but got " .. constructed:variant_name())