Plua
A WIP Lua preprocessor, inspired by Nelua's preprocessor.
Features
- Metaprogramming
- Compile time Lua
- Interpolation
- Metacode includes
- Emit compiler warnings and errors
- Environment globals
- CLI
- Rust crate (API not stable)
- Lua LS plugin
- Editor syntax highlighting
- Vim/Neovim
- VS Code
Syntax and semantics are not yet stable, and may change.
Usage
$ plua --help
Lua preprocessor
Usage: plua [OPTIONS] <SOURCE>
Arguments:
<SOURCE> Source plua file
Options:
-o, --output <OUTPUT> Output directory. If omitted, the source directory will be used
-e, --env <ENV> Pass an environment global in the format name=value
-q, --quiet Supress stdout logging
-d, --debug Enable debug mode. Metaprograms will be written as a .meta.lua file
-h, --help Print help
-V, --version Print version
Example
Plua code:
##!include
local
##[[
function pow(n, e)
return n ^ e
end
]]
log
local hello = "world"
print
print
##
##pfunc
print
##[[
function create_logger(prefix)
return #{
function(msg)
log("[#|prefix|#]: " .. msg)
end
}#
end
]]
local plua_log = #|create_logger|#
plua_log
##[[
Plua.warn("Compiler warning")
-- Plua.error("Compiler error")
]]
Command:
$ plua examples/syntax.plua examples/syntax.lua
WARN [plua] Warning on line 104: Compiler warning
INFO [plua] Wrote lua build\syntax.lua
Resulting Lua code:
print
local
log
local hello = "world"
print
print
local
print
local plua_log =
plua_log
See the examples folder for more.