{"id":20234152,"url":"https://github.com/arbmind/twofold-chaiscript","last_synced_at":"2026-06-08T19:31:00.540Z","repository":{"id":29228698,"uuid":"32760476","full_name":"arBmind/Twofold-ChaiScript","owner":"arBmind","description":"An experimental Twofold implementation based on ChaiScript","archived":false,"fork":false,"pushed_at":"2015-09-22T15:44:37.000Z","size":276,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-03-03T14:12:03.275Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arBmind.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-23T21:41:02.000Z","updated_at":"2015-03-27T20:43:54.000Z","dependencies_parsed_at":"2022-09-05T14:10:10.470Z","dependency_job_id":null,"html_url":"https://github.com/arBmind/Twofold-ChaiScript","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arBmind/Twofold-ChaiScript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arBmind%2FTwofold-ChaiScript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arBmind%2FTwofold-ChaiScript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arBmind%2FTwofold-ChaiScript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arBmind%2FTwofold-ChaiScript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arBmind","download_url":"https://codeload.github.com/arBmind/Twofold-ChaiScript/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arBmind%2FTwofold-ChaiScript/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34078019,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-08T02:00:07.615Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-14T08:08:54.006Z","updated_at":"2026-06-08T19:31:00.522Z","avatar_url":"https://github.com/arBmind.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Twofold\n\n**Generate correctly indented source code with the power of ChaiScript and Qt**\n\nThis is the second C++ implementation of Twofold.\n\n[![Build Status](https://travis-ci.org/arBmind/Twofold-ChaiScript.svg?branch=develop)](https://travis-ci.org/arBmind/Twofold-ChaiScript)\n\n**This is very experimental and not ready for production.**\n\n[hicknhack-software/Twofold-Qt](https://github.com/hicknhack-software/Twofold-Qt) is a production ready version working with Javascript.\n\n## What is the best method to generate source code?\n\n* more difficult than regular html. It requires tight controls about every whitespace and tools for indentation.\n* often requires more control structures in order to access models or AST-like structures.\n\nWe faced these challenges and Twofold is the result.\n\n## Features\n\n* indentation handling\n* source maps for generated script\n  * script exceptions and syntax errors will point into your template\n* nested source maps for generated targets\n  * positions of all the calls that lead to any target character\n* control of every generated line and every whitespace\n* fully unit and integration tested\n\n## Requirements\n\n* C++11 compiler\n  * Tested with GCC 4.9.1 on Linux (Travis) and MinGW (Windows)\n  * Tested with Visual Studio 2013 Community Edition Compiler (x86 and amd64)\n  * Tested with Clang 3.4 on Linux and Clang 3.6 on Windows\n  * Other compilers might work, but are not currently tested\n* Qt 5.4.x\n  * Tested with the binary distributions of Qt 5.4.1 on Linux and Windows\n  * Other Qt versions might work, but are not currently tested\n\n## How does it work?\n\nTwofold is basically ChaiScript that is extended with constructs to generate source code output.\n\n```twofold\n  \\ indented output #{interpolated} without a line break\n  | indented output #{interpolated} with a line break\n  # include \"indent_the_included_file.twofold\"\n  = change_indentation_of_chaiscript()\n// every line is regular ChaiScript\n```\n\nThese control characters have to be the first non-whitespace character on each line.\nEvery whitespace before them is ignored.\nEvery whitespace after is used as the indentation. Indentation is cumulative and added to each generated line.\n\n**Hint:** Use the whitespaces before control characters to indent them in a column deeper than any surrounding ChaiScript.\nThis gives you a visual splitter.\n\nThis is basically everything you need to know.\n\n## Example Template\n\n```twofold\n// file included.twofold\ndef methodArgs(args) {\n  args.for_each_with_index(fun(arg, i){\n    if (0!=i) {\n        // use interpolation to preserve the whitespace\n        \\#{\", \"}\n    }\n    // use backslash to avoid linebreaks\n        \\#{arg}\n  });\n}\ndef showMethod(method) {\n        |function #{method.name}(#{methodArgs(method.args)}) {\n        |  #{method.body}\n        |}\n}\n```\n\n```twofold\n// file main.twofold\n#include \"included.twofold\"\n        |function #{name}Class(#{methodArgs(args)}) {\nmethods.for_each_with_index(fun(method){\n        =  showMethod(method)\n});\n        |\n        |  return {\nmethods.for_each_with_index(fun(method, i){\n        |    \"#{method.name}\": #{method.name}#{(i+1 \u003c methods.size) ? \",\" : \"\"}\n});\n        |  };\n        |}\n```\n\nIf we run this template against the following data. See the BasicUsage example.\n\n```json\n{\n\"name\": \"TwofoldGenerated\",\n\"args\": [],\n\"methods\": [\n  {\n  \"name\": \"hello\",\n  \"args\": [\"greeted\"],\n  \"body\": \"console.log('Hello ' + greeted);\"\n  }\n]\n}\n```\n\nTwofold will generate the following output.\n\n```chaiscript\nfunction TwofoldGenerated() {\n  function hello(greeted) {\n    console.log('Hello ' + greeted);\n  }\n\n  return {\n    \"hello\": hello\n  };\n}\n```\n\n## Roadmap\n\nTwofold is simple. We find it very useful as it is.\n\n* Get ChaiScript faster than JavaScript\n* Improve script error handling\n* feel free to add your wish as an issue\n\n## License\n\nApache License Version 2.0\nSee LICENSE file for more details\n\n## Contribute\n\nIf you like this project give it a star.\nIf you don't like it or found a bug, please write an issue.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farbmind%2Ftwofold-chaiscript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farbmind%2Ftwofold-chaiscript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farbmind%2Ftwofold-chaiscript/lists"}