---
title: Fizz buzz - LuaX demo
date: @DATE
author: @AUTHOR
keywords:
- Lua
- Script
- Documentation
- Tests
- Build system
fontsize: 10pt
---
logo = os.getenv "LOGO"::::::::::::::::::::::::::::: {.columns}
:::::::::: {.column width=50%}
This document is not about Fizzbuzz.
This document is a suggestion to simplify the build process of software projects.
Fizzbuzz is just an application example.
::::::::::
:::::::::: {.column width=40%}
::::::::::
:::::::::::::::::::::::::::::
Lots of software projects involve various tools, free as well as commercial.
- projects are less scalable and harder to maintain
- sharing data is painful and counter productive
e.g.: Bash, Python, Javascript, plain text, YAML, JSON, XML, CSV, INI, TOML, ...
- a common, simple and powerful data format
- and a reduced set of highly configurable tools.
::::::::::::::::::::::::::::: {.columns}
:::::::::: {.column width=48%}
- powerful,
- efficient,
- lightweight,
- embeddable scripting language.
- procedural programming,
- object-oriented programming,
- functional programming,
- data-driven programming,
- and data description.
::::::::::
:::::::::: {.column width=48%}
- proven, robust language
- fast
- portable
- powerful but simple
- small
- free
::::::::::
:::::::::::::::::::::::::::::
::::::::::::::::::::::::::::: {.columns}
:::::::::: {.column width=48%}
- Lua interpreter and REPL
- based on Lua 5.4
- more built-in packages
- multiplatform Lua compiler
- zero dependency
- history
- human-readable tables
F: functional programmingfs: file systemsh: shell commands
::::::::::
:::::::::: {.column width=48%}
mathx:mathextensionimath: arbitrary precisionqmath: rational numberscomplex: complex numbers
crypt: cryptographylz4: compressionlpeg: parsersluasocket: network- ...
https://codeberg.org/cdsoft/luax
::::::::::
:::::::::::::::::::::::::::::
::::::::::::::::::::::::::::: {.columns}
:::::::::: {.column width=48%}
- general programming language
- good documentation
- common data format
- human-readable and structured
- Lua tables
- project configuration
- software configuration
- readable by any Lua interpreter
::::::::::
:::::::::: {.column width=48%}
- documentation generation
- code generation
- test results
- test reports
- requirement coverage
https://codeberg.org/cdsoft/luax
::::::::::
:::::::::::::::::::::::::::::
::::::::::::::::::::::::::::: {.columns}
:::::::::: {.column width=48%}
- Ninja file generator scriptable in LuaX
- Lua/LuaX macros
- compiled with LuaX
- all LuaX modules available in bang build scripts
- bang takes a build description (a LuaX script)
- and generates a Ninja file
::::::::::
:::::::::: {.column width=48%}
- ninja primitives (variables, rules, build statements, ...)
- rule/build statement pairs described in a single function call
- file listing and filenames list management using LuaX modules
- functional programming (LuaX
Fmodule) - pipe simulation using rule composition
- "clean", "install" and "help" targets
https://codeberg.org/cdsoft/bang
::::::::::
:::::::::::::::::::::::::::::
::::::::::::::::::::::::::::: {.columns}
:::::::::: {.column width=48%}
- minimalist and generic text preprocessor
- Lua/LuaX macros
- compiled with LuaX
- all LuaX modules available in ypp macros
- ypp searches for Lua expressions
- and replaces their sources by their results
::::::::::
:::::::::: {.column width=48%}
- Lua expression evaluation
- file inclusion
- conditional text
- functional programming (LuaX
Fmodule) - file management (LuaX
fsmodule) - requirement management (still experimental)
https://codeberg.org/cdsoft/ypp
::::::::::
:::::::::::::::::::::::::::::
::::::::::::::::::::::::::::: {.columns}
:::::::::: {.column width=48%}
@q[=====[
@include "file.md"
@@[[
local foo = 42
N = foo * 23 + 34
local function sq(x)
return x*x
end
function sumsq(n)
return F.range(N)
: map(sq)
: sum()
end
]]
]=====]
@@[[ local foo = 42 N = foo * 23 + 34 local function sq(x) return x*x end function sumsq(n) return F.range(N) : map(sq) : sum() end ]]
::::::::::
:::::::::: {.column width=48%}
@q[=====[
$$
\sum_{i=1}^{@N} i^2 =
@sumsq(N)
$$
]=====]
::::::::::
:::::::::::::::::::::::::::::
::::::::::::::::::::::::::::: {.columns}
:::::::::: {.column width=48%}
Pandoc is a swiss-army knife to convert from and to a bunch of document formats.
Pandoc uses Lua scripts:
- custom readers
- custom writers
- Lua filters on Pandoc AST
::::::::::
:::::::::: {.column width=48%}
Manual:
https://pandoc.org/MANUAL.html
Lua filters:
https://pandoc.org/lua-filters.html
::::::::::
:::::::::::::::::::::::::::::
::::::::::::::::::::::::::::: {.columns}
:::::::::: {.column width=48%}
- Pandoc Lua filters
- variable expansion
- conditional blocks
- file inclusion
- script execution
- diagrams
::::::::::
:::::::::: {.column width=48%}
- based on the Pandoc Lua interpreter
- LuaX specific functions are available
https://codeberg.org/cdsoft/panda
::::::::::
:::::::::::::::::::::::::::::
The Panda doc macro extract documentation (in Markdown) from an external file:
:::{doc=deep_thought.c}
::::::{doc=deep_thought.c} :::
_dot = "{{dot}}"
_gnuplot = "{{gnuplot}}"::::::::::::::::::::::::::::: {.columns}
:::::::::: {.column width=48%}
- code blocks
- replaced by an image by panda.
::::::::::
:::::::::: {.column width=48%}
digraph {
rankdir=LR;
input -> pandoc -> output
pandoc -> panda -> {pandoc, diagrams}
{ rank=same; pandoc, panda }
{ rank=same; diagrams, output }
}::::::::::
:::::::::::::::::::::::::::::
```{.dot render="{{_dot}}"}
digraph {
rankdir=LR;
input -> pandoc -> output
pandoc -> panda -> {pandoc, diagrams}
{ rank=same; pandoc, panda }
{ rank=same; diagrams, output }
}
```::::::::::::::::::::::::::::: {.columns}
:::::::::: {.column width=48%}
- code blocks
- replaced by an image by panda.
::::::::::
:::::::::: {.column width=48%}
set xrange [-pi:pi]
set yrange [-1.5:1.5]
plot sin(x) lw 4, cos(x) lw 4
::::::::::
:::::::::::::::::::::::::::::
```{render="{{_gnuplot}}"}
set xrange [-pi:pi]
set yrange [-1.5:1.5]
plot sin(x) lw 4, cos(x) lw 4
```
::::::::::::::::::::::::::::: {.columns}
:::::::::: {.column width=48%}
- LuaX
- YPP
- Pandoc
- Panda
- requirement database (still experimental)
- tests results
- test report
::::::::::
:::::::::: {.column width=48%}
- examples using ypp and Panda macros
- requirement management
- test execution
- test report
::::::::::
:::::::::::::::::::::::::::::
@@[[ link = F.curry(function(name, url) return F.I{name=name, url=url}"$(name): <$(url)>\n" end) ]]
- @link "Fizzbuzz repository" "https://codeberg.org/cdsoft/fizzbuzz"
- @link "Lua" "https://www.lua.org"
- @link "Lua documentation" "https://www.lua.org/manual/5.4/"
- @link "LuaX" "https://codeberg.org/cdsoft/luax"
- @link "bang" "https://codeberg.org/cdsoft/bang"
- @link "ypp" "https://codeberg.org/cdsoft/ypp"
- @link "Pandoc" "https://pandoc.org"
- @link "Pandoc manual" "https://pandoc.org/MANUAL.html"
- @link "Pandoc Lua filters" "https://pandoc.org/lua-filters.html"
- @link "Panda" "https://codeberg.org/cdsoft/panda"
- @link "LuaX binaries" "https://codeberg.org/cdsoft/pub"
::::::::::::::::::::::::::::: {.columns}
:::::::::: {.column width=48%}
::::::::::
:::::::::: {.column width=48%}
::::::::::
:::::::::::::::::::::::::::::