{"id":20085521,"url":"https://github.com/smarthome-go/homescript","last_synced_at":"2025-05-06T01:33:03.027Z","repository":{"id":43645946,"uuid":"489471641","full_name":"smarthome-go/homescript","owner":"smarthome-go","description":"A custom DSL which provides scripting for the Smarthome Server","archived":false,"fork":false,"pushed_at":"2025-04-14T12:32:51.000Z","size":1938,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"singletons","last_synced_at":"2025-04-14T13:46:26.678Z","etag":null,"topics":["dsl","language","programming-language","scripting","scripting-language","smarthome"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/smarthome-go/homescript","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smarthome-go.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}},"created_at":"2022-05-06T19:29:32.000Z","updated_at":"2025-04-14T12:32:55.000Z","dependencies_parsed_at":"2024-04-14T23:22:05.396Z","dependency_job_id":null,"html_url":"https://github.com/smarthome-go/homescript","commit_stats":{"total_commits":404,"total_committers":3,"mean_commits":"134.66666666666666","dds":"0.10643564356435642","last_synced_commit":"fa901e4cdba4edc30311fdd43c87bb221baa9c52"},"previous_names":[],"tags_count":48,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smarthome-go%2Fhomescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smarthome-go%2Fhomescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smarthome-go%2Fhomescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smarthome-go%2Fhomescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smarthome-go","download_url":"https://codeload.github.com/smarthome-go/homescript/tar.gz/refs/heads/singletons","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252604635,"owners_count":21775131,"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":["dsl","language","programming-language","scripting","scripting-language","smarthome"],"created_at":"2024-11-13T15:56:22.732Z","updated_at":"2025-05-06T01:33:02.659Z","avatar_url":"https://github.com/smarthome-go.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The Homescript DSL (V3)\n\nHomescript is a custom DSL (domain-specific language) for the\n[Smarthome server](https://github.com/smarthome-go/smarthome).\n\nIt provides a scripting interface for Smarthome users in order to allow them to\ncreate customized routines and workflows.\n\nFurthermore, more advanced users can use it to implement their own apps which\nrun inside Smarthome.\n\n## Language overview\n\n- Rust-like syntax\n- Strong type-system\n\n### Statements\n\n#### Type Definition\n\n```rs\ntype Foo = int;\ntype Bar = [ Foo ];\ntype Baz = {\n  a_key: Foo,\n  another_key: Bar,\n};\n```\n\n#### Let Statement\n\n```rs\nlet foo = \"bar\";\nlet foo: MyType = returns_any();\n```\n\n#### Return Statement\n\n```rs\nreturn;\nreturn 42;\n```\n\n#### Different Loop Statements\n\n```rs\nloop {\n  continue;\n  break;\n}\n\nwhile foo \u003c 42 {\n  continue;\n  break;\n}\n\nlet iterator = [1, 2, 3];\n// let iterator = 1..42;\n// let iterator = \"A String\";\n\nfor i in iterator {\n  println(i);\n  continue;\n  break;\n}\n```\n\n#### Expression Statement\n\n```rs\n42;\na_call();\n```\n\n### Expressions\n\n### Literals\n\n```rs\nfn main() {\n    42;                   // integer\n    3.14159265;           // float\n    false;                // bool\n    \"A string\";           // string\n    null;                 // null\n    none;                 // none\n    1..42;                // range\n    [ 1, 2, 3 ];          // list\n    new { key: \"Value\" }; // object\n    fn() -\u003e int {};   // closure\n    ( 42 );               // nested\n    -1;                   // prefix\n    ident = 42;           // assign\n    foo();                // call\n    list[-1];             // index\n    foo.bar;              // member\n    foo as type;          // cast\n\n    try {                 // try-catch\n      /* ... */\n    } catch e {\n      /* ... */\n    }\n\n    if condition {        // if-else\n      /* ... */\n    } else if condition {\n      /* ... */\n    } else {\n      /* ... */\n    }\n\n    {                     // block\n      /* ... */\n      42\n    }\n}\n```\n\n### Types\n\n| Type       | Example which yields this type | Note                                                     |\n| ---------- | ------------------------------ | -------------------------------------------------------- |\n| any        | `\"{}\".parse_json()`            | explicit type-annotations required                       |\n| null       | `null`                         | stands for 'no value'                                    |\n| int        | `42`                           | matches the int64 Go specification                       |\n| float      | `3.14`                         | matches the float64 Go specification                     |\n| bool       | `true`                         | is either `true` or `false`                              |\n| string     | `\"Hello World!\"`               | can hold any UTF-8 character                             |\n| range      | `1..42`                        | specifies a range between two `int` values               |\n| list       | `[ 1, 2 ]`                     | can hold any inner type as long as all elements share it |\n| any-object | `new { ? }`                    | the HMS version of a `map[string]any`                    |\n| object     | `new { key: 1 }`               | no duplicate or builtin keys allowed                     |\n| option     | `?42; none`                    | used for runtime handling of nullable values             |\n| closure    | `fn() -\u003e int {}`               | without an identifier, captures its environment          |\n\n## Examples\n\n### Calculating Fibonacci Numbers\n\n```rs\nfn fib(n: int) -\u003e int {\n    if n \u003c 2 {\n        n\n    } else {\n        fib(n - 1) + fib(n - 2)\n    }\n}\n\nfn main() {\n    for n in 2..40 {\n        println(n.to_string(), \"-\u003e\", fib(n))\n    }\n}\n```\n\n### FizzBuzz\n\n```rs\nfn fizz_buzz(max: int) {\n    for n in (max + 1).to_range() {\n        if n % 15 == 0 {\n            println(\"FizzBuzz\");\n        } else if n % 3 == 0 {\n            println(\"Fizz\");\n        } else if n % 5 == 0 {\n            println(\"Buzz\");\n        } else {\n            println(n);\n        }\n    }\n}\n\nfn main() {\n    fizz_buzz(15);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmarthome-go%2Fhomescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmarthome-go%2Fhomescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmarthome-go%2Fhomescript/lists"}