Component.define makes a live Component Schema, with fields and Awake (#80) #92
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
crowmaki/cinnabar!92
Loading…
Reference in a new issue
No description provided.
Delete branch "component-define"
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?
Closes #80. Part of #75.
What
A Script writes
local Mover = Component.define("game.mover", { speed = 1.5, enabled = true })and gets a live Component Schema in Core.Component.definereads the defaults table; a number picksF64, a boolean picksBool, anything else raises naming the field, which fails the load. Fields are sorted by name so the layout does not depend on table iteration order.defineis legal only while a Script loads.on_addtrampoline. It recovers the Plugin State through the published Interface, writes the defaults into Core storage, then runsAwakeunderpcallwith a traceback handler, all beforecomponent_addreturns. A Luau error inAwakeis logged with the traceback and the Component stays.==is identity within a frame. Reads and writes go throughcomponent_dataand the Schema field offset; the VM holds no Component state. Unknown fields, mistyped values, and a destroyed Component raise, the last namingreadorwrite.One divergence from the issue text: it says "a shared metatable per class". This uses one metatable for every class, since the userdata carries its class pointer and a Luau userdata tag maps to exactly one metatable. Behaviour is identical.
Tests
tests/luau/component_test.odincovers every acceptance criterion from Luau source strings only. The harness the two luau test files shared by copy now lives intests/luau/harness.odin.just checkandjust testpass (420 tests across six suites).