dotlua help to run lua code with bash shell
- Call lua function from shell and vice versa
- Get, set and export shell variables directly from lua
$ enable -f path/to/dotlua.so dotlua
# dot lua
$ dotlua -s 'print(_VERSION)'
# remove
$ enable -d dotlua
It is recommended to start your bash script with env
#!/usr/bin/env bash
# apk add bash (?)
# apk add meson
# apk add lua5.4-dev bash-dev
meson setup builddir
meson compile -C builddir
$ dotlua FILE [ARGUMENTS ...]
$ dotlua [-r] -f FUNCTION [ARGUMENTS ...]
Option -r
allow you to call the raw function.
$ dotlua -s "LUA STRING"
$ dotlua -l [PATTERN]
Set env DOTLUA_PREFIX
to override default namespace sh
-- export foo
sh.put("foo")
-- export foo=bar
sh.put("foo", "bar")
-- foo=bar
sh.set("foo", "bar")
-- $foo
sh.get("foo")
-- unset foo
sh.delete("foo")
sh.bind("add_2_number")
sh.bind("add-2-number", add_2_number)
Call lua function from shell after binding
sh.call("call_two", 1, 2)
Call shell function from lua
Store function bindings
-
dotlua xxx.lua
-
dotlua xxx.lua -- args
-
dotlua -s "string lua"
-
dotlua -f function args
-
dotlua -l match
- call shell built-ins
- call shell
cd
- lua c api fix
- valgrind check
- clang format
- catch stdout/stderr?
- lua function return
- put (export)
- delete (unset)
# apk add bats
bats tests
Copyright (C) 2024 qaqland
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
This project is highly inspired by LuaBash.
Start to make your own builtin from this blog and get more builtin example and details in bash_builtin and bash itself.