{"id":16762218,"url":"https://github.com/richorama/ironblock","last_synced_at":"2025-03-17T02:31:17.727Z","repository":{"id":47163579,"uuid":"111693296","full_name":"richorama/IronBlock","owner":"richorama","description":":arrow_forward: A .net core interpreter for blockly programs","archived":false,"fork":false,"pushed_at":"2024-02-27T10:27:10.000Z","size":20125,"stargazers_count":88,"open_issues_count":12,"forks_count":24,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-13T16:46:20.162Z","etag":null,"topics":["blockly","netcore"],"latest_commit_sha":null,"homepage":"https://richorama.github.io/IronBlock/","language":"C#","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/richorama.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"richorama"}},"created_at":"2017-11-22T14:19:13.000Z","updated_at":"2024-12-07T19:25:26.000Z","dependencies_parsed_at":"2024-10-27T11:52:54.079Z","dependency_job_id":"68fd862b-99e5-4227-afc6-32d02c78e97b","html_url":"https://github.com/richorama/IronBlock","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/richorama%2FIronBlock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richorama%2FIronBlock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richorama%2FIronBlock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richorama%2FIronBlock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/richorama","download_url":"https://codeload.github.com/richorama/IronBlock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243837009,"owners_count":20355813,"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":["blockly","netcore"],"created_at":"2024-10-13T04:44:20.671Z","updated_at":"2025-03-17T02:31:16.985Z","avatar_url":"https://github.com/richorama.png","language":"C#","funding_links":["https://github.com/sponsors/richorama"],"categories":[],"sub_categories":[],"readme":"![ASP.NET Core CI](https://github.com/richorama/IronBlock/workflows/ASP.NET%20Core%20CI/badge.svg)\n\n# IronBlock\n\nA .net core interpreter for [blockly](https://developers.google.com/blockly), allowing you to execute blockly programs in .NET.\n\n## Installation\n\nVia [nuget](https://www.nuget.org/packages/IronBlock):\n\n```\nPM\u003e Install-Package IronBlock\n```\n\nor\n\n```\n\u003e dotnet add package IronBlock\n```\n\n## Basic Usage\n\nFirstly, in JavaScript save your blockly workspace as an XML file:\n\n```js\nvar xml = Blockly.Xml.workspaceToDom(workspace);\n```\n\nThe blockly [code demo](https://blockly-demo.appspot.com/static/demos/code/index.html) allows you to view the XML of your workspace.\n\nThe XML will look something like this:\n\n```xml\n\u003cxml\u003e\n  \u003cblock type=\"text_print\"\u003e\n    \u003cvalue name=\"TEXT\"\u003e\n      \u003cshadow type=\"text\"\u003e\n        \u003cfield name=\"TEXT\"\u003eHello World\u003c/field\u003e\n      \u003c/shadow\u003e\n    \u003c/value\u003e\n  \u003c/block\u003e\n\u003c/xml\u003e\n```\n\nYou'll need to pass this XML to your .NET server using an Ajax call or similar.\n\nYou can then parse the XML, and execute the Blockly program in .NET.\n\n```cs\nusing IronBlock;\nusing IronBlock.Blocks;\n\n// create a parser\nvar parser = new Parser();\n\n// add the standard blocks to the parser\nparser.AddStandardBlocks();\n\n// parse the xml file to create a workspace\nvar workspace = parser.Parse(xml);\n\n// run the workspace\nvar output = workspace.Evaluate();\n\n// \"Hello World\"\n\n// you can optionally pass in a dictionary of variables\nvar args = new Dictionary\u003cstring,object\u003e();\nargs.Add(\"message\", \"Hello!\");\nworkspace.Evaluate(args);\n\n// if your program sets any variable values,\n// you can read then out of the args dictionary \n```\n\n## Custom Blocks\n\nBlockly has a [block designer](https://blockly-demo.appspot.com/static/demos/blockfactory/index.html) allowing you to create your own blocks very easily.\n\nCustom blocks can be implemented in C# by inheriting `IBlock`:\n\n```cs\npublic class MyCustomBlock : IBlock\n{\n    public override object Evaluate(Context context)\n    {\n        // read a field\n        var myField = this.Fields.Get(\"MY_FIELD\");\n        \n        // evaluate a value\n        var myValue = this.Values.Evaluate(\"MY_VALUE\", context);\n        \n        // evaluate a statement\n        var myStatement = this.Statements.Get(\"MY_STATEMENT\");\n        myStatement.Evaluate(context); // evaluate your statement\n\n        // if your block returns a value, simply `return myValue`\n\n        // if your block is part of a statment, and another block runs after it, call\n        base.Evaluate(context);\n        return null;\n    }\n}\n```\n\nYou can then register your block and run it:\n\n```cs\nvar parser = new Parser();\nparser.AddBlock\u003cMyCustomBlock\u003e(\"my_custom_block\");\nvar workspace = parser.Parse(xml);\nworkspace.Evaluate();\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichorama%2Fironblock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frichorama%2Fironblock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichorama%2Fironblock/lists"}