feat(lang): def REGISTRY from "file.lres" - a game fills an open registry from its own file
The entries are read and checked against the registry's record as a registry ... from file is, errors at the resource file's line, and they are defs of the module that wrote the line: the registry must be open to it, and they take that module's place in the stable order. Reseed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a09b622a1d
commit
a5f52c4581
13 changed files with 43732 additions and 43470 deletions
9
examples/modules/crafting/index.ludic
Normal file
9
examples/modules/crafting/index.ludic
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# crafting/index.ludic - a registry the game may add to, and the package's own first entry
|
||||
module crafting
|
||||
export property Recipe {
|
||||
key: string = ""
|
||||
name: string = ""
|
||||
minutes: int = 0
|
||||
}
|
||||
export open registry Recipes of Recipe as RC
|
||||
def Recipes rope { name: "Rope", minutes: 10 }
|
||||
3
examples/modules/recipes.lres
Normal file
3
examples/modules/recipes.lres
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# recipes.lres - the game's own recipes, added to crafting's open registry
|
||||
tea { name: "Pine tea", minutes: 5 }
|
||||
splint { name: "Splint", minutes: 20 }
|
||||
12
examples/modules/registry_extend.ludic
Normal file
12
examples/modules/registry_extend.ludic
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# registry_extend.ludic — L8 + L9: a game fills a package's open registry from its own resource
|
||||
# file with `def Recipes from "recipes.lres"`. The entries are checked against Recipe as the file
|
||||
# is read, and they come after the package's own, in file order.
|
||||
#
|
||||
# Running it prints: 3 Rope Pine tea Splint 20
|
||||
import "crafting"
|
||||
program RegistryExtend {
|
||||
def Recipes from "recipes.lres"
|
||||
entry {
|
||||
print(`{RC_COUNT} {Recipes[0].name} {Recipes[RC_TEA].name} {Recipes[2].name} {Recipes[recipes_find("splint")].minutes}`)
|
||||
}
|
||||
}
|
||||
3
examples/rejected/bad_recipes.lres
Normal file
3
examples/rejected/bad_recipes.lres
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# bad_recipes.lres - the second entry gives minutes as text
|
||||
tea { name: "Pine tea", minutes: 5 }
|
||||
splint { name: "Splint", minutes: "twenty" }
|
||||
8
examples/rejected/craft_kit/index.ludic
Normal file
8
examples/rejected/craft_kit/index.ludic
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# craft_kit/index.ludic - an open registry of recipes
|
||||
module crafting
|
||||
export property Recipe {
|
||||
key: string = ""
|
||||
name: string = ""
|
||||
minutes: int = 0
|
||||
}
|
||||
export open registry Recipes of Recipe as RC
|
||||
8
examples/rejected/registry_extend_field.ludic
Normal file
8
examples/rejected/registry_extend_field.ludic
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# L8 + L9: a resource file that extends a registry is checked against its record, at its own line
|
||||
import "craft_kit"
|
||||
program RegistryExtendField {
|
||||
def Recipes from "bad_recipes.lres"
|
||||
entry {
|
||||
print(RC_COUNT)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue