Skip to content

Latest commit

 

History

History
166 lines (112 loc) · 2.74 KB

README.md

File metadata and controls

166 lines (112 loc) · 2.74 KB

dotlua

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

Usage

$ 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

Setup

# apk add bash (?)
# apk add meson
# apk add lua5.4-dev bash-dev

meson setup builddir
meson compile -C builddir

CLI

Source File

$ dotlua FILE [ARGUMENTS ...]

Call Function

$ dotlua [-r] -f FUNCTION [ARGUMENTS ...]

Option -r allow you to call the raw function.

Execute String

$ dotlua -s "LUA STRING"

List Lua Bindings

$ dotlua -l [PATTERN]

API

Set env DOTLUA_PREFIX to override default namespace sh

sh.put()

-- export foo
sh.put("foo")

-- export foo=bar
sh.put("foo", "bar")

sh.set()

-- foo=bar
sh.set("foo", "bar")

sh.get()

-- $foo
sh.get("foo")

sh.delete()

-- unset foo
sh.delete("foo")

sh.bind()

sh.bind("add_2_number")
sh.bind("add-2-number", add_2_number)

Call lua function from shell after binding

sh.call()

sh.call("call_two", 1, 2)

Call shell function from lua

sh.F

Store function bindings

TODO

  • 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)

Test

# apk add bats

bats tests

LICENSE

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/.

Acknowledge

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.