Component.define makes a live Component Schema, with fields and Awake (#75) #80
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
crowmaki/cinnabar#80
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Parent
#75
What to build
A game developer writes
local Mover = Component.define("game.mover", { speed = 1.5, enabled = true })in a Script and gets a real Component Schema in Core. The default value's Luau type picks the Kind: a number isF64, a boolean isBool; any other value type fails the define with an error naming the field. (TheGameObjectclass as a default marks a Reference field, delivered in a later ticket.)A Component instance reaching Luau is a userdata carrying the Component Handle with a shared metatable per class. Reading
self.speedresolves the field index once per class and reads Core storage throughcomponent_dataand the Schema field offset; writing goes the same way. No Component state lives in the VM. The userdata is cached per Handle in a weak table so identity comparison works within a frame.Defaults are applied in the
on_addtrampoline, thenAwake()runs, before the adding call returns. A Component defined with the same name in two different Scripts fails the second load with a log message.Acceptance criteria
load,engine_component_typefinds the Schema by its defined name with fields matching the define, in the declared Kindscomponent_addreads back the defaults throughcomponent_dataAwakeruns beforecomponent_addreturns; a field it writes is visible from Odin immediately after the callAwakeis logged with a traceback andcomponent_addstill returnsBlocked by