{"id":15038443,"url":"https://github.com/stregasgate/gravity","last_synced_at":"2026-01-02T07:05:34.650Z","repository":{"id":155995639,"uuid":"578331239","full_name":"STREGAsGate/Gravity","owner":"STREGAsGate","description":"Gravity for Swift","archived":false,"fork":false,"pushed_at":"2023-01-08T21:30:06.000Z","size":854,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-13T23:13:28.987Z","etag":null,"topics":["gravity-language","swift-language","swift-linux","swift-mac","swift-package","swift-windows"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/STREGAsGate.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,"publiccode":null,"codemeta":null}},"created_at":"2022-12-14T19:59:51.000Z","updated_at":"2023-09-01T20:16:03.000Z","dependencies_parsed_at":"2023-05-26T00:30:58.298Z","dependency_job_id":null,"html_url":"https://github.com/STREGAsGate/Gravity","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/STREGAsGate%2FGravity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STREGAsGate%2FGravity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STREGAsGate%2FGravity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/STREGAsGate%2FGravity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/STREGAsGate","download_url":"https://codeload.github.com/STREGAsGate/Gravity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243495495,"owners_count":20299923,"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":["gravity-language","swift-language","swift-linux","swift-mac","swift-package","swift-windows"],"created_at":"2024-09-24T20:38:32.355Z","updated_at":"2026-01-02T07:05:34.625Z","avatar_url":"https://github.com/STREGAsGate.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cb\u003e⚠️ Under Heavy Development! Expect sweeping changes followed by a squash.\u003c/b\u003e\n\n# Gravity for Swift\n\n\u003cp align=\"left\" \u003e\n\u003ca href=\"http://gravity-lang.org\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/stregasgate/gravity/master/.github/docs/assets/images/logo-gravity.png\" height=\"74px\" alt=\"Gravity Programming Language\" title=\"Gravity Programming Language\"\u003e\u003c/a\u003e\n\u003ca href=\"https://swift.org\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/stregasgate/gravity/master/.github/docs/assets/images/logo-swift.png\" height=\"74px\" alt=\"Swift Programming Language\" title=\"Swift Programming Language\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n[![Windows](https://github.com/STREGAsGate/Gravity/actions/workflows/Windows.yml/badge.svg)](https://github.com/STREGAsGate/Gravity/actions/workflows/Windows.yml) [![macOS](https://github.com/STREGAsGate/Gravity/actions/workflows/macOS.yml/badge.svg)](https://github.com/STREGAsGate/Gravity/actions/workflows/macOS.yml) [![Linux](https://github.com/STREGAsGate/Gravity/actions/workflows/Linux.yml/badge.svg)](https://github.com/STREGAsGate/Gravity/actions/workflows/Linux.yml) [![WebAssembly](https://github.com/STREGAsGate/Gravity/actions/workflows/SwiftWasm.yml/badge.svg)](https://github.com/STREGAsGate/Gravity/actions/workflows/SwiftWasm.yml)\n\n# What is Gravity for Swift?\n\u003cb\u003eGravity\u003c/b\u003e is a powerful, dynamically typed, lightweight, embeddable programming language. It is a class-based concurrent scripting language with a modern Swift like syntax.\n\n\u003cb\u003eGravity for Swift\u003c/b\u003e is a Swift Package that allows you to use the Gravity language with your Swift projects.\n\n# Getting Started\n\u003ci\u003eThis README does not cover the Gravity language. \u003c/br\u003e\nBefore jumping in you should familiarize yourself with [Gravity's documentation](http://gravity-lang.org).\u003c/i\u003e\n\n## Adding Gravity for Swift to your Project\nYou can add \u003cb\u003eGravity for Swift\u003c/b\u003e to a package:\n```swift\nlet package = Package(\n    name: \"MyThing\",\n    dependencies: [\n        // Add Gravity as a package dependency so it's available to your target\n        .package(url: \"https://github.com/STREGAsGate/Gravity.git\", branch: \"master\"),\n    ],\n    targets: [\n        // Add Gravity to your target dependencies\n        // This will make Gravity available to `import Gravity`\n        .executableTarget(name: \"MyThing\", dependencies: [\"Gravity\"]),\n    ]\n)\n```\n\u003csub\u003eIf you are using an ***Xcode Project*** you can add gravity by selecting your project in the navigator, your project at the top of the targets list, and finally the ***Package Dependencies*** tab.\u003c/sub\u003e\u003c/br\u003e\n\n## Running a Gravity script\n```swift\nimport Gravity\n\n// The Gravity object handles everything.\nlet gravity = Gravity()\n\n// Compile script from a URL\nlet bundleURL = Bundle.module.resourceURL!\nlet scriptURL = bundleURL.appendingPathComponent(\"File.gravity\")\ntry gravity.compile(scriptURL)\n  \n// Execute the script's func main()\ntry gravity.runMain()\n```\n\nA Gravity script can also be compiled from a string.\n```swift\ntry gravity.compile(\"func main() {}\")\n```\n\nSome actions must be done in a specific order. \u003c/br\u003e\nFor example, you cannot call `runMain()` before calling `compile(script)`.\n\u003c/br\u003e\u003c/br\u003e\n# Obtaining Values\nYou can retrieve a value from the script in various ways.\n\n### Global Variables\nA global variable is any variable in the root of a script.\n```swift\n/* --- Gravity Script --- */\nvar myVar = 10 // \u003c- This is a global variable\nfunc main() {}\n```\nYou can obtain the value of a global variable using `gravity.getVar(\"myVar\")`.\n```swift\n// The GravityValue type is the universal return type for Gravity\nlet myVarGravity: GravityValue = gravity.getVar(\"myVar\")\n// Make sure it's an Int\nassert(myVarGravity.valueType == .int)\n// Ask for the Int\nlet myVar: Int = myVarGravity.getInt()\n\n// The Int can also be obtained directly by declarting myVar as an Int\nlet myVar: Int = gravity.getVar(\"myVar\")\n```\n\n### Return Values\nAll Closures in Gravity return a value, but you can ignore the value if you know it's empty\n```swift\n// Ignoring the return value\ntry gravity.runMain()\n// Storing the return value\nlet result = try gravity.runMain()\n```\n\n# C99 Access\nYou can access the unmodifed c99 Gravity source directly via the Swift module GravityC.\n```swift\nimport GravityC\n```\n\u003csub\u003eNote: Using the GravityC module requires significant knowledge of Swift's Unsafe API and is not recommended.\u003c/sub\u003e\n\n# Strega's Gate\n[![Twitter](https://img.shields.io/twitter/follow/stregasgate?style=social)](https://twitter.com/stregasgate) [![YouTube](https://img.shields.io/youtube/channel/subscribers/UCBXFkK2B4w9856wBJfCGufg?label=Subscribe\u0026style=social)](https://youtube.com/stregasgate) [![Reddit](https://img.shields.io/reddit/subreddit-subscribers/stregasgate?style=social)](https://www.reddit.com/r/stregasgate/) [![Discord](https://img.shields.io/discord/641809158051725322?label=Hang%20Out\u0026logo=Discord\u0026style=social)](https://discord.gg/5JdRJhD)\n\nCheck out what I'm working on at various places or come say hi on discord!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstregasgate%2Fgravity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstregasgate%2Fgravity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstregasgate%2Fgravity/lists"}