{"id":20914788,"url":"https://github.com/tinybiggames/cscript","last_synced_at":"2025-04-11T09:14:45.906Z","repository":{"id":263397076,"uuid":"890269628","full_name":"tinyBigGAMES/CScript","owner":"tinyBigGAMES","description":"C99 Scripting Engine","archived":false,"fork":false,"pushed_at":"2024-11-25T19:53:46.000Z","size":19292,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-11T07:09:22.451Z","etag":null,"topics":["c-embedded-in-delphi","c-script","c99","delphi","dll","exe","lib","pascal","win64","windows10","windows11"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tinyBigGAMES.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"tinyBigGAMES","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"thanks_dev":null,"custom":null}},"created_at":"2024-11-18T09:35:12.000Z","updated_at":"2024-12-29T13:31:43.000Z","dependencies_parsed_at":"2024-11-18T11:11:03.252Z","dependency_job_id":null,"html_url":"https://github.com/tinyBigGAMES/CScript","commit_stats":null,"previous_names":["tinybiggames/cscript"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyBigGAMES%2FCScript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyBigGAMES%2FCScript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyBigGAMES%2FCScript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyBigGAMES%2FCScript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinyBigGAMES","download_url":"https://codeload.github.com/tinyBigGAMES/CScript/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248365781,"owners_count":21091840,"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":["c-embedded-in-delphi","c-script","c99","delphi","dll","exe","lib","pascal","win64","windows10","windows11"],"created_at":"2024-11-18T16:10:57.549Z","updated_at":"2025-04-11T09:14:45.888Z","avatar_url":"https://github.com/tinyBigGAMES.png","language":"C","readme":"![CScript](media/cscript.png)  \n[![Chat on Discord](https://img.shields.io/discord/754884471324672040?style=for-the-badge)](https://discord.gg/tPWjMwK)\n[![Follow on Bluesky](https://img.shields.io/badge/Bluesky-tinyBigGAMES-blue?style=for-the-badge\u0026logo=bluesky)](https://bsky.app/profile/tinybiggames.com)\n\n# 🅲🆂cript\n\n**🅲🆂cript** represents a sophisticated 🅲99 scripting engine meticulously crafted for experienced 🧑‍💻 Delphi developers. Leveraging the compact yet highly versatile **TinyCC** compiler, **🅲🆂cript** seamlessly integrates ⚙️ dynamic backend code generation into the Delphi development environment. With **🅲🆂cript**, Delphi developers can 🛠️ compile and execute 🅲 scripts at runtime, directly in 💾 memory, and generate output in the form of 🪟 Win64 executables (.exe), dynamic-link libraries (.dll), or 📂 object files (.obj).\n\n### ✨ Features\n\n- **⚙️ Dynamic Code Generation**: Facilitates runtime 🛠️ compilation and execution of 🅲99 code directly within the Delphi application context.\n- **🖥️ Versatile Output Options**: Supports in-memory execution alongside output to executable, DLL, or object file formats.\n- **📦 Effortless Integration with 🅲 Libraries**: Capable of loading and interacting with compiled modules, including `.dll`, `.a`, and `.lib` files.\n- **📂 Embedded Resources**: TinyCC runtime components (.h, .a, .o files) are encapsulated within a compressed zip resource and linked directly into your Delphi executable, thus minimizing 🗂️ file system dependencies while ensuring runtime availability.\n- **⚠️ Customizable Error Handling**: Offers the ability to assign custom error handlers, streamlining 🐞 debugging and enabling robust error management.\n- **🔍 Full Symbol Access**: Provides direct access to symbols generated by the compiled code and to symbols within dynamically loaded modules, simplifying the integration of complex functionalities.\n\n### 🛠️ How It Works\n\n**🅲🆂cript** employs **TinyCC**, which is statically linked into the Delphi runtime, to compile and execute 🅲 code dynamically. All critical 🅲 runtime I/O operations—such as `open`, `close`, `read`, and `lseek`—are re-routed to Delphi-native implementations. Typically, TinyCC would require runtime files to be available separately; however, in **🅲🆂cript**, these files are stored within the Delphi executable itself as compressed resources, resulting in a 📦 self-contained virtualized I/O model. When **TinyCC** requests access to runtime files, a custom Delphi I/O handler checks the embedded zip archive, thereby ensuring a seamless, efficient, and isolated execution environment.\n\n### 🧩 Integration with Delphi\n\n**🅲🆂cript** functions as a conduit to harness the capabilities of 🅲99 code within the Delphi development framework. Whether it involves optimizing particular operations for ⚡ enhanced performance, interfacing with pre-existing 🅲 libraries, or augmenting Delphi's feature set with the expressive capabilities of 🅲, **🅲🆂cript** provides a cohesive and sophisticated development toolset.\n\n### 🗝️ Key Classes and Types\n\n**TCScript** is the primary interface for engaging with **🅲🆂cript** functionalities. Below is an overview of its core components:\n\n#### 🅃CScriptOutputType\n- `csMEMORY`: 🛠️ Compile and execute scripts entirely in memory.\n- `csLib`: Generate 📂 object files (`.obj`).\n- `csEXE`: Generate a 🪟 Win64 executable.\n- `csDLL`: Generate a 📄 dynamic-link library.\n\n#### 🅃CScriptExeSubsystem\n- `csCONSOLE`: Targets 🎮 console application subsystems.\n- `csGUI`: Targets 🎨 graphical user interface subsystems.\n\n#### 🅃CScript Class Overview\n- **🏗️ Construction and Destruction**\n  - `constructor Create()`: 🛠️ Initializes an instance of **TCScript**.\n  - `destructor Destroy()`: 💣 Releases resources tied to the **TCScript** instance.\n- **⚠️ Error Handling**\n  - `procedure SetErrorHandler(const ASender: Pointer; const AHandler: TCScriptErrorEvent)`: Assigns a custom error handler for error management.\n  - `procedure GetErrorHandler(var ASender: Pointer; var AHandler: TCScriptErrorEvent)`: Retrieves the currently assigned error handler.\n- **📂 Path Management**\n  - `function AddLibraryPath(const APath: string): Boolean`: Registers a 📁 library path for the compiler.\n  - `function AddIncludePath(const APath: string): Boolean`: Registers an include path for locating header files.\n- **🛠️ Compilation and Execution**\n  - `function SetOutputType(const AOutputType: TCScriptOutputType): Boolean`: Specifies the desired output type for script compilation.\n  - `function CompileString(const ABuffer: string): Boolean`: Compiles a provided string of 🅲 code.\n  - `function AddFile(const AFilename: string): Boolean`: Adds a 📄 source file to the compilation unit.\n  - `function Run(): Boolean`: Executes the compiled script.\n- **📦 Library Management**\n  - `function AddLibrary(const AName: string): Boolean`: Adds an external library to be dynamically linked during execution.\n- **🔍 Symbol Management**\n  - `procedure AddSymbol(const AName: string; AValue: Pointer)`: Registers a symbol to the scripting context.\n  - `function GetSymbol(const AName: string): Pointer`: Retrieves the address of a registered symbol.\n- **🛠️ Utility Functions**\n  - `procedure Reset()`: Resets the **TCScript** instance, clearing previous states.\n  - `function SaveOutputFile(const AFilename: string): Boolean`: Saves the compiled output to a specified 📄 file.\n\n### 📖 Example Usage\n\nThe following example illustrates how to instantiate **TCScript**, add a file for compilation, and execute the resulting script:\n\n```delphi\nprocedure CScriptErrorEvent(const ASender: Pointer; const AText: string);\nbegin\n  WriteLn(AText);\nend;\n\nprocedure AddFileRun();\nvar\n  LCScript: TCScript;\nbegin\n  LCScript := TCScript.Create();\n  try\n    // Set the ⚠️ error handler\n    LCScript.SetErrorHandler(nil, CScriptErrorEvent);\n    \n    // Configure the output type for in-memory execution\n    LCScript.SetOutputType(csMEMORY);\n    \n    // Add include and library paths\n    LCScript.AddIncludePath('res/include');\n    LCScript.AddLibraryPath('res/lib');\n    \n    // Add the 🅲 source file to the scripting engine\n    LCScript.AddFile('res/src/test01.c');\n    \n    // Execute the compiled script\n    if not LCScript.Run() then\n      WriteLn('❌ Failed to execute script.');\n  finally\n    // Release resources\n    LCScript.Free();\n  end;\nend;\n```\n\n### Prerequisites\n- **Delphi 12 CE or higher** 🖥️\n- **Windows 10 or higher** 🪟\n- **Tested on Windows 11 64-bit (23H2), Delphi 12.2** ✅\n\n### 🛠️ Installation\n\nTo integrate **🅲🆂cript** into your Delphi project:\n\n1. **⬇️ Download the latest version** from the **🅲🆂cript** repository.\n2. **📦 Unzip** to your desired location.\n3. **➕ Add the `src` folder** to the Delphi search path.\n4. **➕ Add `🅲🆂cript` to your project's uses section**.\n5. **📖 See the examples** for more information on usage.\n\n### 🤝 Contributions\n\nContributions to **🅲🆂cript** are highly encouraged. Please feel free to submit issues, suggest new features, or create pull requests to expand the capabilities and robustness of the scripting engine.\n\n### 📝 License\n\n**🅲🆂cript** is distributed under the 🆓 BSD-3-Clause license. For more details, refer to the `LICENSE` file.\n\n### Support\n\n- \u003ca href=\"https://github.com/tinyBigGAMES/CScript/issues\" target=\"_blank\"\u003eIssues\u003c/a\u003e\n- \u003ca href=\"https://github.com/tinyBigGAMES/CScript/discussions\" target=\"_blank\"\u003eDiscussions\u003c/a\u003e\n- \u003ca href=\"https://github.com/tinyBigGAMES/CScript/wiki\" target=\"_blank\"\u003eWiki\u003c/a\u003e\n- \u003ca href=\"https://learndelphi.org/\" target=\"_blank\"\u003eLearn Delphi\u003c/a\u003e\n\n---\n\nWhether you seek to ⚡ enhance computational performance, interface seamlessly with existing 🅲 libraries, or expand the features of your Delphi applications, **🅲🆂cript** provides a powerful, integrated solution for combining the strengths of Delphi and 🅲99 programming.\n\n🔓 Unlock new possibilities with **🅲🆂cript** and elevate your Delphi development experience through hybrid programming techniques.\n\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"media/delphi.png\" alt=\"Delphi\"\u003e\n\u003c/p\u003e\n\u003ch5 align=\"center\"\u003e\n\nMade with :heart: in Delphi\n\u003c/h5\u003e\n\n","funding_links":["https://github.com/sponsors/tinyBigGAMES"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinybiggames%2Fcscript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinybiggames%2Fcscript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinybiggames%2Fcscript/lists"}