Pointer despawn limit
Console program87 lines of .st181 lines of generated C
after despawn: 9
On this page
The .st files#
intent.st
structop {
type_app {
exec = {
lang = "C"
}
}
lib_provider {
core = {
source = "StructOp/c"
version = "@latest"
}
}
}main.st
# Language 7.6.9: a pointer to an entity component used after despawn is accepted and not checked;
# it points at the slot's next user and never reads outside the component storage. C only: the
# Rust target does not yet store the address of a component field in a value (it refuses it).
ability "component" "Hp" {
fields = [{ name = "n", type = Int }]
}
ability "value" "e" {
type = Int
}
data "value" "e" {
of = ability.value.e
}
ability "value" "cp" {
type = Pointer
to = Int
}
data "value" "cp" {
of = ability.value.cp
}
ability "spawn" "Old" {
components = {
Hp = {
n = 5
}
}
entity = ability.value.e
}
ability "function" "aim" {
body = [ability.query.Aim]
}
ability "query" "Aim" {
with = [Hp]
bind = {
h = Hp
}
body = [ability.set.AimHp]
}
ability "call" "Aim" {
function = ability.function.aim
depends_on = [ability.spawn.Old]
}
ability "set" "AimHp" {
target = ability.value.cp
value = address_of(h.n)
}
ability "despawn" "Old" {
entity = data.value.e.current
depends_on = [ability.call.Aim]
}
ability "spawn" "New" {
components = {
Hp = {
n = 9
}
}
depends_on = [ability.despawn.Old]
}
ability "print" "AfterDespawn" {
message = "after despawn: ${value_at(data.value.cp.current)}"
depends_on = [ability.spawn.New]
}Input, plan and generated C#
structop plan
structop plan
# program.app will be created
+ program.app (.structop/build/app)
+ ability.component.Hp
+ ability.value.e
+ ability.value.cp
+ ability.spawn.Old
+ ability.function.aim
+ ability.query.Aim
+ ability.call.Aim
+ ability.set.AimHp
+ ability.despawn.Old
+ ability.spawn.New
+ ability.print.AfterDespawn
Plan: 1 to add, 0 to change, 0 to destroy.Generated main.c
To inspect this generated file, select C in intent.st, initialize the project and export its source.
Export locally
structop init
structop apply -source -no-runTry it
cd pointer-despawn-limit # a folder holding the .st files above
structop init
structop plan
structop apply