The problem#
When developing the "garbage collector" for the
Pacifist mod, I noted that I couldn't actually know which string
s
should be treated as references. As a workaround, I just assumed all
string
s were references, which worked well enough, but I wondered if
there was a way to get more precise type information. Additionally,
when I was trying to figure this out, the developer of exfret's
randomizer expressed interest in getting access to
such information for that mod.
The solution#
The Factorio documentation includes a machine-readable
version of the prototype API
documentation. My ReflectionLibrary
mod provides access to that information from within a
Factorio mod, effectively faking a reflection API
for type information on data.raw
during the Prototype
Stage:
local data_raw = ReflectionLibraryMod.typed_data_raw
local bb = data_raw['blueprint-book']['blueprint-book']
log(bb.inventory_size._type.typeKind) # prints "literal"
bb.inventory_size = 42
log(bb.inventory_size._type.typeKind) # prints "alias"
log(bb.inventory_size._type.name) # prints "ItemStackIndex"