calclib/README.md

83 lines
4.5 KiB
Markdown
Raw Permalink Normal View History

2026-02-03 10:08:09 -03:00
# Library calclib Stubs
2026-01-02 10:50:29 +00:00
2026-01-02 11:57:31 -03:00
## Overview
2026-02-03 10:08:09 -03:00
This project, `calclib`, is a crucial component within the **KnitPkg for MetaTrader** Demo ecosystem,
designed to facilitate the consumption of `@douglasrechia/calclibimp` by other KnitPkg projects. It acts
2026-01-02 11:57:31 -03:00
as a "stub" package, providing the necessary header files (`.mqh`) with `#import` directives that allow other
MQL5 Expert Advisors, Indicators, or Scripts to seamlessly call functions implemented in a separate, compiled
library. The project is intended **only as an educational example** of how to structure, package and compile
2026-01-07 14:53:07 -03:00
MQL5 code with KnitPkg – it is **not** meant to be a production‑grade library for large‑scale use.
2026-01-02 11:57:31 -03:00
2026-02-03 10:08:09 -03:00
By separating the library's interface (stubs) from its implementation, `calclib` promotes a clean,
2026-01-07 14:53:07 -03:00
modular architecture. This approach enhances code reusability and simplifies dependency management for complex MQL5 projects. It demonstrates how KnitPkg can be used to link different components effectively, enabling robust and scalable development.
2026-01-02 11:57:31 -03:00
## Features
2026-01-07 14:53:07 -03:00
* **KnitPkg Dependency Management**: Demonstrates how a package can be structured to export functionality
from a library, making it discoverable and manageable via the KnitPkg CLI.
* **Facilitates Library Consumption**: Simplifies the process for other KnitPkg projects to utilize functions
2026-01-02 11:57:31 -03:00
from compiled MQL5 and/or DLL libraries, abstracting away the complexities of direct library linking.
* **Library Stub Generation**: Provides header files with `#import` directives, allowing MQL5 projects to
2026-02-03 10:08:09 -03:00
call functions from `@douglasrechia/calclibimp` compiled `.ex5` library.
2026-01-02 11:57:31 -03:00
* **Decoupling of Interface and Implementation**: Separates the function declarations from their actual
implementation, promoting a cleaner architectural design.
* **Unit Testing**: Includes unit tests to verify that the library stubs correctly link to the underlying
implementation and that the exported functions behave as expected.
## Prerequisites
To use this project, you will need:
1. **MetaTrader 5**: With MetaEditor 5 installed.
2026-01-07 14:53:07 -03:00
2. **KnitPkg CLI**: The KnitPkg package manager for MetaTrader. If you don't have it, you can install it by
following the instructions in the [main KnitPkg repository](https://github.com/knitpkg-dev/knitpkg-mt.git).
2026-01-02 11:57:31 -03:00
3. **`CalcLibImp.ex5`**: The compiled library from the
2026-02-03 10:08:09 -03:00
[`@douglasrechia/calclibimp`](https://forge.mql5.io/DouglasRechia/@douglasrechia/calclibimp.git) project must be
2026-01-02 11:57:31 -03:00
present in your MetaTrader's `MQL5/Libraries` directory. This package provides the stubs for that specific
library.
2026-02-03 10:08:09 -03:00
## Adding `calclib` as a dependency in your project
2026-01-02 11:57:31 -03:00
2026-02-03 10:08:09 -03:00
To incorporate the latest stable release of `calclib` into your KnitPkg project, use the `add` command to include it as a dependency in your `knitpkg.yaml` file:
2026-01-02 11:57:31 -03:00
2026-02-03 10:08:09 -03:00
```bash
kp add @douglasrechia/calclib
2026-01-02 11:57:31 -03:00
```
2026-02-03 10:08:09 -03:00
Note that the caret (^) prefixing the version number in the `knitpkg.yaml` manifest indicates that your project will receive minor and patch updates for `calclib` during installation commands.
After adding the dependency, execute `kp install` to download `calclib` for prompt use. For reproducible builds, you may opt to use `kp install --locked` to adhere to the locked version. Refer to the KnitPkg documentation for additional information.
2026-01-02 11:57:31 -03:00
## Unit Tests
This package includes unit tests to verify that the `SMA_Close_TimeSeries` stub correctly links to the `CalcLibImp.ex5` library and returns accurate results.
To run the unit tests:
```bash
# Change to your MetaTrader 'Scripts' directory.
# How to find it: in the MetaEditor navigator, right‑click the `Scripts` folder and select "Open Folder".
cd "C:\Users\username\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Scripts"
# Clone the repository
2026-02-03 10:08:09 -03:00
git clone https://forge.mql5.io/DouglasRechia/calclib.git
2026-01-02 11:57:31 -03:00
2026-02-03 10:08:09 -03:00
cd calclib
2026-01-02 11:57:31 -03:00
# Compile the test script
2026-02-03 10:08:09 -03:00
kp compile
2026-01-02 11:57:31 -03:00
# Close MetaTrader and launch it again (needed to refresh navigator Scripts). Open any chart you want.
2026-02-03 10:08:09 -03:00
# The compiled binary `UnitTests.ex5` will appear in MetaTrader navigator under the Scripts/calclib entry.
2026-01-02 11:57:31 -03:00
# Double‑click it to run the tests. See test results in the 'Scripts' tab.
```
## License
This project is released under the **MIT License**. See the `LICENSE` file for the full text.
## Disclaimer
*The author provides this code **as‑is**, for **educational purposes only**.
No warranty, express or implied, is given. The author assumes **no liability** for any damages, losses, or legal consequences that may arise from using, modifying, or distributing this software. Use it at your own risk.*