Skip to content

Commit

Permalink
add Lua support
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Delord authored and CDSoft committed Jul 11, 2018
1 parent 467610c commit ec23be1
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 64 deletions.
32 changes: 26 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ repository.
- [Bash](https://www.gnu.org/software/bash/),
[Cmd](https://en.wikipedia.org/wiki/Cmd.exe),
[PowerShell](https://en.wikipedia.org/wiki/PowerShell),
[Python](https://www.python.org/),
[Python](https://www.python.org/), [Lua](http://www.lua.org/),
[Haskell](https://www.haskell.org/) and
[R](https://www.r-project.org/) scripts

Expand Down Expand Up @@ -360,6 +360,8 @@ preprocessing it.
`!python2(CMD)` executes `CMD` with Python 2.
- **`python3`**
`!python3(CMD)` executes `CMD` with Python 3.
- **`lua`**
`!lua(CMD)` executes `CMD` with Lua.
- **`haskell`**
`!haskell(CMD)` executes `CMD` as a Haskell script with
`runhaskell`.
Expand Down Expand Up @@ -825,7 +827,7 @@ Once generated the image looks like:

This script outputs:

Hi, I'm /bin/bash 4.4.19(1)-release
Hi, I'm /bin/bash 4.4.23(1)-release
Here are a few random numbers: 17766, 11151, 23481

**Note**: the keyword `sh` executes `sh` which is generally a link to
Expand All @@ -852,7 +854,7 @@ This script outputs:

Hi, I'm C:\windows\system32\cmd.exe

Microsoft Windows 10.0.15063 (3.8)
Microsoft Windows 10.0.15063 (3.11)
This script is run from wine under Linux

### Python
Expand All @@ -878,6 +880,24 @@ This script outputs:
[GCC 8.1.1 20180502 (Red Hat 8.1.1-1)]
Here are a few random numbers: 640, 25, 275

### Lua

[Lua](http://www.lua.org/) is executed when the keyword `lua` is used.

!lua
~~~~~
print("Hi, I'm ".._VERSION)
math.randomseed(42)
t = {}
for i = 1, 3 do table.insert(t, math.random(0, 999)) end
print("Here are a few random numbers: "..table.concat(t, ", "))
~~~~~

This script outputs:

Hi, I'm Lua 5.3
Here are a few random numbers: 329, 690, 422

### Haskell

[Haskell](https://www.haskell.org/) is executed when the keyword
Expand All @@ -903,7 +923,7 @@ This script outputs:

This script outputs:

Hi, I'm Haskell 8.2
Hi, I'm Haskell 8.4
The first 10 prime numbers are: 2 3 5 7 11 13 17 19 23 29

### Stack
Expand All @@ -914,7 +934,7 @@ beginning of the script.

!stack
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{- stack script --resolver lts-11.8 --package base -}
{- stack script --resolver lts-12.0 --package base -}

import System.Info
import Data.Version
Expand All @@ -934,7 +954,7 @@ beginning of the script.

This script outputs:

Hi, I'm Haskell 8.2
Hi, I'm Haskell 8.4
The first 10 prime numbers are: 2 3 5 7 11 13 17 19 23 29

### R (script)
Expand Down
6 changes: 3 additions & 3 deletions doc/img/pp-plantuml-example.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions doc/img/pp-scripts.dot
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ digraph {
Bash [shape=box label="bash"]
Sh [shape=box label="sh"]
Python [shape=box label="python"]
Lua [shape=box label="lua"]
Haskell [shape=box label="runhaskell"]
Stack [shape=box label="stack"]
Rscriptexe [shape=box label="Rscript"]
Expand All @@ -21,6 +22,7 @@ digraph {
bash -> Bash
sh -> Sh
python -> Python
lua -> Lua
haskell -> Haskell
stack -> Stack
Rscript -> Rscriptexe
Expand Down
80 changes: 49 additions & 31 deletions doc/img/pp-scripts.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 26 additions & 9 deletions doc/pp.html

Large diffs are not rendered by default.

34 changes: 31 additions & 3 deletions doc/pp.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The default macro execution character is redefined to avoid lots of `raw` calls
[Cmd]: https://en.wikipedia.org/wiki/Cmd.exe
[PowerShell]: https://en.wikipedia.org/wiki/PowerShell
[Python]: https://www.python.org/
[Lua]: http://www.lua.org/
[Haskell]: https://www.haskell.org/
[Stack]: https://docs.haskellstack.org/en/stable/README/
[GitHub]: https://github.com/CDSoft/pp
Expand All @@ -48,7 +49,7 @@ And finally [PP] which merges the functionalities of [GPP] and [DPP].
- literate programming
- [GraphViz], [PlantUML] and [ditaa] diagrams
- [Asymptote] and [R] figures
- [Bash], [Cmd], [PowerShell], [Python], [Haskell] and [R] scripts
- [Bash], [Cmd], [PowerShell], [Python], [Lua], [Haskell] and [R] scripts

Open source
===========
Expand Down Expand Up @@ -472,6 +473,7 @@ digraph {
Bash [shape=box label="bash"]
Sh [shape=box label="sh"]
Python [shape=box label="python"]
Lua [shape=box label="lua"]
Haskell [shape=box label="runhaskell"]
Stack [shape=box label="stack"]
Rscriptexe [shape=box label="Rscript"]
Expand All @@ -482,6 +484,7 @@ digraph {
bash -> Bash
sh -> Sh
python -> Python
lua -> Lua
haskell -> Haskell
stack -> Stack
Rscript -> Rscriptexe
Expand Down Expand Up @@ -805,6 +808,31 @@ if __name__ == "__main__":
~~~~~
~~~~~~~~~~

### Lua
[Lua] is executed when the keyword `lua` is used.

!lua
~~~~~
print("Hi, I'm ".._VERSION)
math.randomseed(42)
t = {}
for i = 1, 3 do table.insert(t, math.random(0, 999)) end
print("Here are a few random numbers: "..table.concat(t, ", "))
~~~~~

This script outputs:

~~~~~~~~~~
§lua
~~~~~
print("Hi, I'm ".._VERSION)
math.randomseed(42)
t = {}
for i = 1, 3 do table.insert(t, math.random(0, 999)) end
print("Here are a few random numbers: "..table.concat(t, ", "))
~~~~~
~~~~~~~~~~

### Haskell

[Haskell] is executed when the keyword `haskell` is used.
Expand Down Expand Up @@ -855,7 +883,7 @@ In this case stack meta data must be added at the beginning of the script.

!stack
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{- stack script --resolver lts-11.8 --package base -}
{- stack script --resolver lts-12.0 --package base -}

import System.Info
import Data.Version
Expand All @@ -878,7 +906,7 @@ This script outputs:
~~~~~~~~~~
§stack
~~~~~
{- stack script --resolver lts-11.8 --package base -}
{- stack script --resolver lts-12.0 --package base -}
import System.Info
import Data.Version
Expand Down
Loading

0 comments on commit ec23be1

Please sign in to comment.