Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Structs#11

Merged
fergalwalsh merged 10 commits into
developfrom
structs
Nov 21, 2022
Merged

Structs#11
fergalwalsh merged 10 commits into
developfrom
structs

Conversation

@fergalwalsh

Copy link
Copy Markdown
Collaborator

This PR adds a new language construct: struct
Structs are backed by byte strings. The underlying Teal uses extract & replace.

Structs also form the foundation for support for Boxes.

struct Item:
    id: int
    foo: int
    name: bytes[10]
    description: bytes[20]
end

Item item1 = bzero(46)

item1.id = 123
item1.foo = 999
item1.name = "abc"
item1.description = "ABCDEF"

# manually extract a field from the bytes
log(itob(extract_uint64(item1, 0)))

# access a struct field by name 
log(item1.name)

TODO: tests & docs

@fergalwalsh fergalwalsh merged commit c70dd9b into develop Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant