{"id":13608316,"url":"https://github.com/bitdotgames/bhl","last_synced_at":"2025-12-24T13:47:17.026Z","repository":{"id":37451989,"uuid":"274432365","full_name":"bitdotgames/BHL","owner":"bitdotgames","description":"BHL is a strictly typed programming language based on C# specifically tailored for gameplay logic scripting.","archived":false,"fork":false,"pushed_at":"2025-04-09T15:29:22.000Z","size":7920,"stargazers_count":39,"open_issues_count":0,"forks_count":10,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-09T16:26:55.995Z","etag":null,"topics":["csharp","dotnet","interpreted-programming-language","scripting-language","strongly-typed","unity-3d"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitdotgames.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-06-23T14:48:30.000Z","updated_at":"2025-04-09T15:29:25.000Z","dependencies_parsed_at":"2023-09-23T07:57:12.115Z","dependency_job_id":"5f7837ba-a378-448b-be30-e6a6b8cd3b16","html_url":"https://github.com/bitdotgames/BHL","commit_stats":null,"previous_names":[],"tags_count":256,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitdotgames%2FBHL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitdotgames%2FBHL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitdotgames%2FBHL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitdotgames%2FBHL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitdotgames","download_url":"https://codeload.github.com/bitdotgames/BHL/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248581356,"owners_count":21128155,"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":["csharp","dotnet","interpreted-programming-language","scripting-language","strongly-typed","unity-3d"],"created_at":"2024-08-01T19:01:26.320Z","updated_at":"2025-12-24T13:47:17.019Z","avatar_url":"https://github.com/bitdotgames.png","language":"C#","readme":"# **B**ehaviour **H**ighlevel **L**anguage\n\n![CI](https://github.com/bitdotgames/bhl/actions/workflows/main.yml/badge.svg)\n\n\u003e **BHL** is a strictly typed programming language specifically tailored for gameplay logic scripting. It combines pseudo parallel execution primitives with familiar imperative coding style.\n\nFirst time it was presented at the [nucl.ai](https://nucl.ai/) conference in 2016. Here's the [presentation slides](https://docs.google.com/presentation/d/1As-bw3pY5pLij86j7nf_ycaG0Hb2EqnrwR3R8ID47sQ/edit?usp=sharing). \n\nPlease note that BHL is in beta state and currently targets only C# platform. Nonetheless it has been battle tested in the real world projects and heavily used by BIT.GAMES for mobile games development built with [Unity](https://unity.com/).\n\n## BHL features\n\n* [ANTLR](http://www.antlr.org/) based: C# frontend + C# interpreting backend\n* Statically typed\n* Cooperative multitasking support\n* Built-in support for pseudo parallel code orchestration\n* Golang alike *defer*\n* Basic types: *float, int, bool, string, enums, arrays, maps*\n* Supports imperative style control constructs: *if/else, while, foreach, break, continue, return*\n* Allows user defined: *functions, lambdas, classes, interfaces*\n* Supports C# bindings to user types and functions\n* Passing arguments to function by *ref* like in C#\n* Multiple returned values like in Golang\n* Strict control over memory allocations \n\n## Documentation\n\nFor comprehensive documentation of all BHL features and usage, see the [language documentation](docs/README.md).\n\n## Quick example\n\n```go\ncoro func GoToTarget(Unit u, Unit t) {\n  NavPath path\n  defer {\n    PathRelease(path)\n  }\n  \n  paral {\n   yield while(!IsDead(u) \u0026\u0026 !IsDead(t) \u0026\u0026 !IsInRange(u, t))\n   \n   {\n     path = yield FindPathTo(u, t)\n     yield Wait(1)\n   }\n   \n   {\n     yield FollowPath(u, path)\n   }\n}\n```\n\n## Code samples\n\n### Structs\n\n```go\nclass Color3 {\n  float r\n  float g\n  float b\n}\n\nclass Color4 : Color3 {\n  float a\n}\n\nColor4 c = {}\nc.r = 0.9\nc.g = 0.5\nc.b = 0.7\nc.a = 1.0\n```\n\n### Enums\n\n```go\nenum Status {\n  None       = 0\n  Connecting = 1\n  Connected  = 2\n}\n\nStatus s = Status.Connected\n\n```\n\n### Generic initializers\n\n```go\nclass Vec3 {\n  float x\n  float y\n  float z\n}\n\nVec3[] vs = [{x: 10}, {y: 100, z: 100}, {y: 1}]\n```\n\n### Passing by **ref**\n\n```go\n\nUnit FindTarget(Unit self, ref float dist_to_target) {\n...\n  dist_to_target = u.position.Sub(self.position).length\n  return u\n}\n\nfloat dist_to_target = 0\nUnit u = FindTarget(self, ref dist_to_target)\n```\n### **Multiple returned values**\n\n```go\n\nUnit,float FindTarget(Unit self) {\n...\n  float dist_to_target = u.position.Sub(self.position).length\n  return u,dist_to_target\n}\n\nUnit u,float dist_to_target = FindTarget(self)\n```\n\n### **Closures**\n\n```go\nUnit u = FindTarget()\nfloat distance = 4\nu.InjectScript(coro func() {\n  paral_all {\n    yield PushBack(distance: distance)\n    yield Stun(time: 0.4, intensity: 0.15)\n  }\n})\n```\n\n### Function pointers\n\n```go\nfunc bool(int) p = func bool(int b) { return b \u003e 1 }\nreturn p(10)\n```\n\n### **defer** support\n\n```go\n{\n  RimColorSet(color: {r:  0.65, a: 1.0}, power: 1.1)\n  defer { RimColorSet(color: {a: 0}, power: 0) }\n     ... \n}\n```\n\n### Pseudo parallel code execution\n\n```go\ncoro func Attack(Unit u) {\n  Unit t = TargetInRange(u)\n  Check(t != null)\n  paral_all {\n   yield PlayAnim(u, trigger: \"Attack\")\n   SoundPlay(u, sound: \"Swoosh\")\n   {\n     yield WaitAnimEvent(u, event: \"Hit\")\n     SoundPlay(u, sound: \"Damage\")\n     yeld HitTarget(u, t, damage: RandRange(1,16))\n   }\n}\n```\n\n### Example of some unit's top behavior\n\n```go\ncoro func Selector([]coro func bool() fns) {\n  foreach(var fn in fns) {\n    if(!yield fn()) {\n      continue\n    } else {\n      break\n    }\n  }\n}\n\ncoro func UnitScript(Unit u) {\n  while(true) {\n    paral {\n      yield WaitStateChanged(u)\n      Selector(\n            [\n              coro func bool() { return yield FindTarget(u) },\n              coro func bool() { return yield AttackTarget(u) },\n              coro func bool() { return yield Idle(u) }\n            ]\n       )\n    }\n    yield()\n  }\n}\n```\n\n## Architecture\n\n![BHL architecture](https://puu.sh/qEkYv/edf3b678aa.png)\n\nBHL utilizes a standard interpreter architecture with a **frontend** and a **backend**. Frontend is responsible for reading input files, static type checking and bytecode generation. Binary bytecode is post-processed and optimized in a separate stage. Processed byte code can be used by the backend. Backend is a interpreter responsible for runtime bytecode evaluation. Backend can be nicely integrated with [Unity](https://unity.com/). \n\n### Frontend\n\nIn order to use the frontend you can use the **bhl** tool which ships with the code. See the quick build example below for instructions.  \n \n\n## Quick build example\n\nCurrently BHL assumes that you have [dotnet]([https://dotnet.microsoft.com/]) installed and its binaries are in your PATH.\n\n\nJust try running *run.sh* script: \n\n\u003e cd example \u0026\u0026 ./run.sh\n\nThis example executes the following [ simple script ](example/unit.bhl)\n\n```markdown\nUnit starts...\nNo target in range\nIdling 3 sec...\nState changed!\nIdle interrupted!\nFound new target 703! Approaching it.\nAttacking target 703\nTarget 703 is dead!\nFound new target 666! Approaching it.\nState changed!\nFound new target 902! Approaching it.\n...\n```\n\nPlease note that while BHL works fine under Windows, the example script assumes you are using \\*nix platform.\n\n## Examples\n\nBHL comes with example code in the `example` directory that demonstrates key language features:\n\n### Bindings Example\nLocated in `example/bindings/`, this example shows:\n- How to integrate BHL with C# code through bindings\n- Using coroutines (`coro func`) for asynchronous behavior\n- Parallel execution with `paral` blocks\n- State management and event handling\n\nThe example implements a simple AI behavior system with:\n```bhl\ncoro func Unit() {\n  Trace(\"Unit starts...\")\n  int state = 0\n  int target_id = 0\n\n  paral {\n    yield RandomStateChanger(ref state)\n    while(true) {\n      paral {\n        yield StateChanged(ref state)\n        yield Selector(\n          [\n            coro func bool() { return yield AttackTarget(ref target_id) },\n            coro func bool() { return yield FindTarget(ref target_id) },\n            coro func bool() { return yield Idle() }\n          ]\n        )\n      }\n      yield()\n    }\n  }\n}\n```\n\n## Quick Build\n\n\n## Building\n\nBHL comes with its own simple build tool **bhl**. bhl tool is written in C# and should work just fine both on \\*nix and Windows platforms. \n\nIt allows you to compile BHL sources into a binary, lauch an LSP server etc. \n\nYou can view all available build tasks with the following command:\n\n\u003e $ bhl help\n\n## Tests\n\nThere are many [unit tests](test.cs) which cover all BHL features.\n\nYou can run unit tests by executing the following command:\n\n\u003e $ cd tests \u0026\u0026 dotnet test\n\n# Roadmap\n\n## Version 4.0\n\n1. Generics support\n1. JIT support \n1. Weak references semantics\n\n## Version 3.0\n\n1. More optimal runtime memory storage layout\n1. DAP support\n1. LSP support\n\n## Version 2.0\n\n1. ~~Byte code optimization~~\n1. ~~More optimal executor (VM)~~\n1. ~~Better runtime errors reporting~~\n1. ~~More robust type system~~\n1. ~~User class methods~~\n1. ~~Interfaces support~~\n1. ~~Namespaces support~~\n1. ~~Polymorphic class methods~~\n1. ~~Nested classes~~\n1. ~~Nested in classes enums~~\n1. ~~Static class members support~~\n1. ~~Variadic function arguments~~\n1. ~~Maps support~~\n1. ~~Built-in strings basic routines~~\n1. ~~Implicit variable types using 'var'~~ \n1. ~~Basic debugger support~~\n\n## Version 1.0\n\n1. ~~**ref** semantics similar to C#~~\n1. ~~Generic functors support~~\n1. ~~Generic initializers~~\n1. ~~Multiple return values support~~\n1. ~~**while** syntax sugar: **for(...) {}** support~~\n1. ~~**while** syntax sugar: **foreach(...) {}** support~~\n1. ~~Ternary operator support~~\n1. ~~User defined structs~~\n1. ~~User defined enums~~\n1. ~~Postfix increment/decrement~~\n","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitdotgames%2Fbhl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitdotgames%2Fbhl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitdotgames%2Fbhl/lists"}