{"id":13743868,"url":"https://github.com/thosakwe/t2b","last_synced_at":"2025-04-06T07:12:58.549Z","repository":{"id":97961651,"uuid":"136994267","full_name":"thosakwe/t2b","owner":"thosakwe","description":"A wicked-powerful text macro language for building binary files.","archived":false,"fork":false,"pushed_at":"2023-08-09T22:12:26.000Z","size":1963,"stargazers_count":377,"open_issues_count":8,"forks_count":9,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-30T05:09:06.115Z","etag":null,"topics":["command-line","macros","programming-language","t2b"],"latest_commit_sha":null,"homepage":"https://thosakwe.github.io/t2b/index.html","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thosakwe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2018-06-12T00:05:52.000Z","updated_at":"2025-03-22T11:05:51.000Z","dependencies_parsed_at":"2024-01-15T00:39:00.545Z","dependency_job_id":null,"html_url":"https://github.com/thosakwe/t2b","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thosakwe%2Ft2b","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thosakwe%2Ft2b/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thosakwe%2Ft2b/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thosakwe%2Ft2b/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thosakwe","download_url":"https://codeload.github.com/thosakwe/t2b/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247445671,"owners_count":20939958,"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":["command-line","macros","programming-language","t2b"],"created_at":"2024-08-03T05:00:58.671Z","updated_at":"2025-04-06T07:12:58.524Z","avatar_url":"https://github.com/thosakwe.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"# t2b\nA wicked-powerful text macro language for building binary files.\nSupports comments, looping, Unicode, variables, conditionals, macros and recursion.\n\nTLDR; Check out `example/`.\n\nPre-built binaries are available for Win64 and MacOS64.\n\n## Usage\n```bash\n$ t2b \u003cfilename\u003e here\n$ t2b # Read directly from stdin\n```\n\n`t2b` always writes to stdout. To output to a file, simply use a greater-than sign (`\u003e`).\n\n## Language\nNewlines are solely for the sake of readability; all whitespace is the same.\n\n```t2b\n# This is a comment!\n#\n# Comments must be on their own line.\n\n# Emit a byte. In DECIMAL.\nu8 10\n\n# Emit a byte in hex.\nu8 0xa\n\n# Octal\nu16 0o777\n\n# And, of course, binary.\nu8 0b00001110\n\n# Spit out a signed integer.\ni64 25677\n\n# Print a string (no line break)\nstr hello\n\n# Print with a line break.\nstrl hello\n\n# Wrap in quotes to capture whitespace.\nstrl \"hello world!\"\n\n# Escapes are supported.\nstr \"hello, world!\\n\"\n\n# Unicode?\nstr \"\\u{1234}\"\n\n# Print a newline.\nendl\n\n# Do something 5 times.\n# Indentation is purely for readability.\ntimes 5\n    u8 23\n    u32 24\n    times 10\n        # We can nest loops\n        str \"50 times!!!\"\n    endtimes\nendtimes\n\n# Capture the output of another command.\n# Oh, and store it into a variable.\nset foo (u8 33)\n\n# Access its value.\nset bar (get foo)\n\n# Emit its value 3 times.\ntimes 3 get foo endtimes\n\n# Create a simple macro.\nmacro emit_twice x\nbegin\n    times 2 (get x)\nendmacro\n\n# Call it!\nemit_twice 24\n```\n\n## Why?\nThe need for such a program arose when I was working on writing a simple VM.\nManually hex-editing files for an ever changing bytecode spec is tedious, error-prone,\nand most of all - *sucky*.\n\nNow there's a lightweight way to do just that.\n\n## Supported Commands\n* `u8...u64` - Emit unsigned integer\n* `i8...i64` - Emit signed integer\n* `f` - Emit float\n* `d` - Emit double\n* `hex` - Toggle hex mode on/off (defaults to OFF)\n* `str \u003cexpr\u003e` - Write a string\n* `strl \u003cexpr\u003e` - Write a string AND newline\n* `endl` - Write a newline\n* `not \u003cexpr\u003e` Boolean NOT a char\n* `if \u003ccond\u003e \u003cpred\u003e endif` Execute `\u003cpred\u003e` if `\u003ccond\u003e == 1`\n* `get \u003cexpr\u003e` - Fetch the global variable named `expr`\n* `set \u003cexpr1\u003e \u003cexpr2\u003e` - Assign the global variable named `expr1` to `expr2`\n* `=` - Compare two values, return `0` or `1`\n* `times \u003ccount\u003e \u003cpred\u003e endtimes` - Execute `\u003cpred\u003e` `\u003ccount\u003e` times. `i` is always set to the current iteration's index.\n* `macro \u003cname\u003e \u003cparam-names...\u003e begin \u003cpred\u003e endmacro` - Declare a custom macro named `\u003cname\u003e`.\n* `return` - End termination of the current macro. Exits the script if not in a macro.\n* `size` - Return the size of an item\n* `len` - Equivalent to C `strlen`\n\n# What's next?\nIt's now feasible to write a machine code compiler in shell. Hooray.\nNot sure why you would ever do that to yourself, though.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthosakwe%2Ft2b","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthosakwe%2Ft2b","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthosakwe%2Ft2b/lists"}