1 unstable release
Uses new Rust 2024
new 0.1.0 | Mar 11, 2025 |
---|
#316 in Programming languages
58 downloads per month
26KB
696 lines
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 "lib"
local function log(msg)
##if debug then
print(msg)
##end
end
##[[
function pow(n, e)
return n ^ e
end
]]
log(#[pow(2, 4)]#)
local hello = "world"
print(#["hello"]#)
print(#|"hello"|#)
##function pfunc(name, fn)
local function #|name|#()
return pcall(#|fn|#)
end
##end
##pfunc("throw_error", #{function()
error("Throwing!")
end}#)
print(throw_error())
##[[
function create_logger(prefix)
return #{
function(msg)
log("[#|prefix|#]: " .. msg)
end
}#
end
]]
local plua_log = #|create_logger("Plua")|#
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("Hello from plua include!")
local function log(msg)
print(msg)
end
log(16.0)
local hello = "world"
print("hello")
print(hello)
local function throw_error()
return pcall(function()
error("Throwing!")
end)
end
print(throw_error())
local plua_log = function(msg)
log("[Plua]: " .. msg)
end
plua_log(":)")
See the examples folder for more.
Dependencies
~13–24MB
~357K SLoC