CLSH - A Lua scripting host written in C
! This is a very early proof of concept
CLSH is a Lua scripting host written in C.
You can build clsh using cmake, first verify that cmake and a c++ compiler is installed. The Lua sources are included in the lib/lua directory, therefore no external packages or an internet connection is required.
cmake --version
#cmake version 3.30.0
#
#CMake suite maintained and supported by Kitware (kitware.com/cmake).
clang --version
#Apple clang version 15.0.0 (clang-1500.3.9.4)
#Target: arm64-apple-darwin23.5.0
#Thread model: posix
#InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
now run the steps below to compile and run the code
mkdir build
cd build
cmake ..
make
./clsh
# usage: ./clsh [file]
Currently the only supported usage is by providing a lua file as the first argument to CLSH.
Example:
./clsh
./clsh
# usage: ./clsh [file]
./clsh ../scripts/test.lua
# Hi from test.lua
Alternatively you can use the shebang notation to run the lua scripts directly, to do this some preperation is necessary.
- Copy the clsh binary to a directory in your path
echo $PATH
cp ./clsh /dir/in/path/clsh
# example:
# I have a directory called $HOME/bin containing the clsh binary
mkdir ~/bin
echo "export PATH=$PATH:$HOME/bin >> .zshrc
cp ./clsh $HOME/bin/clsh
- Now create a lua script with the shebang line. You can find an example under scripts/shebang.lua
#!/usr/bin/env clsh
-- test.lua
print("Hi from shebang.lua")
- Check the permissions for the lua script, if you are using this method the script itself has to be executable
chmod +x ./scripts/shebang.lua
./scripts/shebang.lua
# Hi from shebang.lua
- (optional) copy the script to a location within your path
cp shebang.lua $HOME/bin/shebang
shebang
# Hi from shebang.lua
CLSH is licensed under the MIT License.