2022-01-30 20:53:26 +01:00
# Calculon
2022-01-30 21:22:55 +01:00
A basic math library to package Teal project with LuaRocks.
Calculon is a simple library written with the Teal language that is packaged with LuaRocks.
The `consumer-project` is another LuaRocks project using Teal that tries to use the Calculon library.
2022-01-30 15:48:10 +01:00
![Calculon ](doc/Calculon.webp "Calculon" )
2022-01-30 21:22:55 +01:00
# TODO
* ~~The consumer works only because the generated file can find the module thanks to `./lua` that includes paths to locally installed packages~~ → is it really an issue?
* ~~Distribute teal files in the rock~~ → I think the rock should be Lua only (+ types definition for teal optionally)
* To not commit generated Lua files, the calculon module can have a `generate-rock` script that build and package the module (Can be done from a CI/CD like GitHub Actions 💡)
* The type definition trick works by abusing Luarocks specs, this needs to me standardized
2022-01-30 15:48:10 +01:00
# Logbook
## e18f54c977 init
2022-01-30 20:53:26 +01:00
Initialize a teal project with `cyan init` , then write the `calculon.tl` Lua.
2022-01-30 15:48:10 +01:00
Note : I also added `.gitignore` and `.gitkeep` files to not commit generated
files from `cyan build` .
## d24e69a41e add(consumer) init
2022-01-30 20:53:26 +01:00
Add a Lua consumer script to try the calculon lib. It can be run with:
2022-01-30 15:48:10 +01:00
```sh
lua consumer.lua
```
Notes :
* We need to first build the lib with `cyan build`
* The consumer needs to require calculon from the build directory
## a433eb2fe4 add(luarocks) init
2022-01-30 20:53:26 +01:00
Initialize a Luarocks module in the current directory.
2022-01-30 15:48:10 +01:00
I need to add the module `calculon = "build/calculon/init.lua"` to make the
rock not empty.
## b4d00c05ae add(build) force commit lua
2022-01-30 20:53:26 +01:00
Because the rock needs the generated Lua, I have force commit it 😭
2022-01-30 15:48:10 +01:00
## acb833e8e1 add(consumer) load calculon as module
2022-01-30 20:53:26 +01:00
Now that the calculon lib ships the Lua files, the consumer can load it as a normal module!
2022-01-30 15:48:10 +01:00
## 5eb06ccafb chore(consumer) move it to a project
Move the consumer to its own project with Luarocks.
2022-01-30 20:53:26 +01:00
Notes : Calculon is not uploaded to Luarocks repositories. We need to install calculon manually from the rockspec file with: `./luarocks install ../calculon-0.1-1.rockspec`
2022-01-30 15:48:10 +01:00
## dac8260ea9 add(consumer) teal
Move the consumer to teal!
2022-01-30 20:53:26 +01:00
It can be built with `tl build` . Then run with `./lua build/consumer.lua` .
2022-01-30 15:48:10 +01:00
Note :
* To prevent the missing types definition error, I need to use the trick from tabular module
2022-01-30 20:53:26 +01:00
* We can't run the teal file directly `tl run src/consumer.tl` 😭
# 72c84c39e6 add(d.tl) calculon type definition
Add type definition to the calculon module and package.
Note : We force the type definition to be part of the module by abusing the `build.install.lua` table.
# 3baa006cb0 add(consumer) use type definitions
The consumer module doesn't need any trick thanks to the type definition file being part of the rock!
Note : We need to include the `lua_modules/share/lua/5.4` path to the tlconfig for this to work
2022-01-30 15:48:10 +01:00
# References
* https://github.com/teal-language/tl/blob/master/docs/tutorial.md
* https://github.com/teal-language/cyan
* https://github.com/teal-language/teal-types
* https://github.com/hishamhm/tabular
2022-01-30 20:53:26 +01:00
Image from https://futurama.fandom.com/wiki/Calculon