
??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).
.dll, .a, and .lib files.??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.
??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.
TCScript is the primary interface for engaging with ??cript functionalities. Below is an overview of its core components:
csMEMORY: Compile and execute scripts entirely in memory.csLib: Generate object files (.obj).csEXE: Generate a ? Win64 executable.csDLL: Generate a ? dynamic-link library.csCONSOLE: Targets ? console application subsystems.csGUI: Targets ? graphical user interface subsystems.constructor Create(): Initializes an instance of TCScript.destructor Destroy(): ? Releases resources tied to the TCScript instance.procedure SetErrorHandler(const ASender: Pointer; const AHandler: TCScriptErrorEvent): Assigns a custom error handler for error management.procedure GetErrorHandler(var ASender: Pointer; var AHandler: TCScriptErrorEvent): Retrieves the currently assigned error handler.function AddLibraryPath(const APath: string): Boolean: Registers a ? library path for the compiler.function AddIncludePath(const APath: string): Boolean: Registers an include path for locating header files.function SetOutputType(const AOutputType: TCScriptOutputType): Boolean: Specifies the desired output type for script compilation.function CompileString(const ABuffer: string): Boolean: Compiles a provided string of ? code.function AddFile(const AFilename: string): Boolean: Adds a ? source file to the compilation unit.function Run(): Boolean: Executes the compiled script.function AddLibrary(const AName: string): Boolean: Adds an external library to be dynamically linked during execution.procedure AddSymbol(const AName: string; AValue: Pointer): Registers a symbol to the scripting context.function GetSymbol(const AName: string): Pointer: Retrieves the address of a registered symbol.procedure Reset(): Resets the TCScript instance, clearing previous states.function SaveOutputFile(const AFilename: string): Boolean: Saves the compiled output to a specified ? file.The following example illustrates how to instantiate TCScript, add a file for compilation, and execute the resulting script:
procedure CScriptErrorEvent(const ASender: Pointer; const AText: string);
begin
WriteLn(AText);
end;
procedure AddFileRun();
var
LCScript: TCScript;
begin
LCScript := TCScript.Create();
try
// Set the ️ error handler
LCScript.SetErrorHandler(nil, CScriptErrorEvent);
// Configure the output type for in-memory execution
LCScript.SetOutputType(csMEMORY);
// Add include and library paths
LCScript.AddIncludePath('res/include');
LCScript.AddLibraryPath('res/lib');
// Add the ? source file to the scripting engine
LCScript.AddFile('res/src/test01.c');
// Execute the compiled script
if not LCScript.Run() then
WriteLn(' Failed to execute script.');
finally
// Release resources
LCScript.Free();
end;
end;To integrate ??cript into your Delphi project:
src folder to the Delphi search path.??cript to your project's uses section.Contributions 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.
??cript is distributed under the ? BSD-3-Clause license. For more details, refer to the LICENSE file.
Whether 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.
? Unlock new possibilities with ??cript and elevate your Delphi development experience through hybrid programming techniques.
Made with ❤️ in Delphi