Skip to content

[feature] Backreferences in format strings #14

@ToxicFrog

Description

@ToxicFrog

It should be possible to refer to already-read values in an easy way, rather than needing to make multiple calls to unpack. For example, length prefixed strings, which are currently:

local length = unpack("u4", true)
local str = unpack("s" .. length, true)

Could instead be:

local str = unpack("length:u4 s$length", true)

Current idea for backref syntax is that $name is a backref and can be used anywhere a number is allowed, e.g. "$count * { x:u4 y:u4 z:u4 }" is also legal. "name" can be a number ($1 being the first non-named value read), a simple name ($length), or a dot-separated identifier ($toc.count).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions