GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - zzmodules/format: String format macros for ZZ

BranchesTags
Open more actions menu

Latest commit

 

History

1 Commit
1 Commit

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
src
src
 
 
tests
tests
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
zz.toml
zz.toml
 
 

Repository files navigation

format

String format macros for ZZ

Installation

Add this to your zz.toml file:

[dependencies]
format = "*"

[repos]
format = "git://github.com/zzmodules/format"

Usage

using format

API

@format::with(fmt, ...)

Creates a formatted string from a variety of special tokens with traditional printf style specifiers supported.

Tokens

  • {} - Treats argument like a struct, calling .display() for a char *
  • {*} - Treats argument like a pointer to a struct, calling ->display() for a char *
  • {0..9} - References argument by position. Treatment is the same as {}
  • {*0..9} - References pointer argument by position. Treatment is same as {*}
  • {$0..9} - References argument identifier name by position and uses it inline
  • {0..9%X} - References argument by position with format. Treatment is like a limited printf

Display Interface

The @format::with() macro will treat struct and struct pointers specified with {}, {*}, and its variant as special input that should implement a displayable interface. Structs should simply implement a display() -> char * method like in the example below:

using format
using log
using string

struct Vector {
  float x;
  float y;
}

fn display(Vector *self) -> char * {
  new+64000 out = string::make();
  out.format("Vector { x: %0.2f, y: %0.2f }", self->x, self->y);
  return out.cstr();
}

fn main() -> {
  let vec = Vector { x: 1.23, y: 2.46 };
  log::info("%s", @format::with("{}", vec)); // Vector { x: 1.23, y: 2.46 }
  return 0;
}

License

MIT

About

String format macros for ZZ

Resources

Readme
MIT license
Activity
Custom properties

Stars

3 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.