{"id":19599710,"url":"https://github.com/starwing/lua-fmt","last_synced_at":"2025-04-27T16:32:07.831Z","repository":{"id":137297190,"uuid":"264939743","full_name":"starwing/lua-fmt","owner":"starwing","description":"A fmtlib implement for Lua","archived":false,"fork":false,"pushed_at":"2025-02-03T13:08:02.000Z","size":59,"stargazers_count":39,"open_issues_count":2,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-05T01:32:12.574Z","etag":null,"topics":["fmtlib","lua"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/starwing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-18T12:56:36.000Z","updated_at":"2025-02-11T09:51:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"24abcca0-dd1b-49aa-b977-fc31ad76b3fb","html_url":"https://github.com/starwing/lua-fmt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starwing%2Flua-fmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starwing%2Flua-fmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starwing%2Flua-fmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starwing%2Flua-fmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/starwing","download_url":"https://codeload.github.com/starwing/lua-fmt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251171448,"owners_count":21547112,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fmtlib","lua"],"created_at":"2024-11-11T09:12:13.103Z","updated_at":"2025-04-27T16:32:07.825Z","avatar_url":"https://github.com/starwing.png","language":"Lua","readme":"# lua-fmt - A fmtlib implement for Lua\n\n[![Build Status](https://travis-ci.org/starwing/lua-fmt.svg?branch=master)](https://travis-ci.org/starwing/lua-fmt)[![Coverage Status](https://coveralls.io/repos/github/starwing/lua-fmt/badge.svg?branch=master)](https://coveralls.io/github/starwing/lua-fmt?branch=master)\n\n\nLua-fmt is a fmt like simple C module for Lua to format string.\n\nThe format syntax is same with\n[fmtlib](https://fmt.dev/latest/syntax.html), which is same with\nPython's `format` routine.\n\n## Install\n\nThe simplest way to install it is using Luarocks:\n\n```shell\nluarocks install --server=https://luarocks.org/dev lua-fmt\n```\n\nOr, just compile the single C file:\n\n```shell\n# Linux\ngcc -o lfmt.so -O3 -fPIC -shared lfmt.c\n# macOS\ngcc -o lfmt.so -O3 -fPIC -shared -undefined dynamic_lookup lfmt.c\n# Windows\ncl /Fefmt.dll /LD /MT /O2 /DLUA_BUILD_AS_DLL /Ipath/to/lua/include lfmt.c path/to/lua/lib\n```\n\n# Example\n\n```lua\nlocal fmt = require \"fmt\"\n\n-- automatic indexed argument\nprint(fmt(\"{} {} {}\", 1,2, 3)) --\u003e \"1 2 3\"\n\n-- manual indexed argument\nprint(fmt(\"{2}, {1}\", \"World\", \"Hello\")) --\u003e \"Hello, World\"\n\n-- named indexed argument\nprint(fmt(\"{name} is {type}\", { name = \"foo\", type = \"bar\" })) --\u003e \"foo is bar\"\nprint(fmt(\"{t.name} is {t.type}\", {t = { name = \"foo\", type = \"bar\" }})) --\u003e \"foo is bar\"\n\n-- format specifier\nprint(fmt(\"{:b}\", 42)) --\u003e \"101010\"\n\n```\n\n## Document\n\nMostly same as [fmtlib](https://fmt.dev/latest/syntax.html).\n\nFormat strings contain “replacement fields” surrounded by curly braces\n`{}`. Anything that is not contained in braces is considered literal\ntext, which is copied unchanged to the output. If you need to include\na brace character in the literal text, it can be escaped by doubling:\n`{{` and `}}`.\n\nThe grammar for a replacement field is as follows:\n\n```\nreplacement_field ::=  \"{\" [arg_id] [\":\" format_spec] \"}\"\narg_id            ::=  field_name accessor*\nfield_name        ::=  integer | identifier\naccessor          ::=  \".\" field_name | \"[\" key_name \"]\"\nkey_name          ::=  field_name | \u003cany chars except ']'\u003e*\ninteger           ::=  digit+\ndigit             ::=  \"0\"...\"9\"\nidentifier        ::=  id_start id_continue*\nid_start          ::=  \"a\"...\"z\" | \"A\"...\"Z\" | \"_\"\nid_continue       ::=  id_start | digit\n```\n\nthe mainly difference is the support of accessor, which is supported\nby Python but not by fmtlib.\n\n- - -\n\n“Format specifications” are used within replacement fields contained\nwithin a format string to define how individual values are presented.\nEach formattable type may define how the format specification is to be\ninterpreted.\n\nMost built-in types implement the following options for format\nspecifications, although some of the formatting options are only\nsupported by the numeric types.\n\nThe general form of a standard format specifier is:\n\n```\nformat_spec ::=  [[fill]align][sign][\"#\"][\"0\"][width][grouping][\".\" precision][type]\nfill        ::=  \u003ca character other than '{' or '}'\u003e\nalign       ::=  \"\u003c\" | \"\u003e\" | \"^\"\nsign        ::=  \"+\" | \"-\" | \" \"\nwidth       ::=  integer | \"{\" [arg_id] \"}\"\ngrouping    ::=  \"_\" | \",\"\nprecision   ::=  integer | \"{\" [arg_id] \"}\"\ntype        ::=  int_type | flt_type | str_type\nint_type    ::=  \"b\" | \"B\" | \"d\" | \"o\" | \"x\" | \"X\" | \"c\"\nflt_type    ::=  \"e\" | \"E\" | \"f\" | \"F\" | \"g\" | \"G\" | \"%\"\nstr_type    ::=  \"p\" | \"s\"\n```\n\nDifferences (all exists in Python):\n- add grouping support for int_type: `\"{:_}\"` e.g. `\"10_000\"`\n- add `\"%\"` specifier for float type: `\"{:%}\"` e.g. `\"100.0%\"`\n\nLua type vs. type specifiers:\n| Lua Type  | Type specifiers    |\n| --------- | ------------------ |\n| \"integer\" | `int_type` |\n| \"float\"   | `flt_type` |\n| Others    | `str_type` |\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarwing%2Flua-fmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstarwing%2Flua-fmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarwing%2Flua-fmt/lists"}