Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
/bin/
/obj/
Makefile
*.make
bin
obj
.cache


*.log


.cache/


.vscode/


.DS_Store
Thumbs.db

build-tracer.lisp
7 changes: 7 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[submodule "lib/compat53"]
path = lib/compat53
url = https://github.com/lunarmodules/lua-compat-5.3.git
[submodule "lib/hashmap"]
path = lib/hashmap
url = https://github.com/tidwall/hashmap.c.git

77 changes: 77 additions & 0 deletions install
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why rename the file instead of using the .sh extension

Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/sh

# Function to install packages using apt (Debian/Ubuntu)
install_with_apt() {
sudo apt-get update
sudo apt-get install -y lua5.4 liblua5.4-dev
}

# Function to install packages using yum (Red Hat/CentOS)
install_with_yum() {
sudo yum install -y epel-release
sudo yum install -y lua lua-devel
}

# New package manager used in Fedora
install_with_dnf() {
sudo dnf install -y lua lua-devel
}

# Function to install packages using pacman (Arch Linux)
install_with_pacman() {
sudo pacman -Sy --noconfirm lua
}

if [ -f /etc/arch-release ]; then
install_with_pacman
elif [ -f /etc/debian_version ]; then
install_with_apt
elif [ -f /etc/redhat-release ] || [ -f /etc/centos-release ]; then
if command -v dnf >/dev/null 2>&1; then
install_with_dnf
else
install_with_yum
fi
else
echo "Your linux distro is not supported currently."
echo "You need to manually install these packages: lua and your distro's lua dev package"
fi

PREMAKE_VERSION="5.0.0-beta2"
OS="linux"

echo "downloading premake $PREMAKE_VERSION"
wget -q https://github.com/premake/premake-core/releases/download/v${PREMAKE_VERSION}/premake-${PREMAKE_VERSION}-${OS}.tar.gz -O premake.tar.gz
echo "extracting premake"
tar -xzf premake.tar.gz
echo "installing premake"
sudo mv premake5 example.so libluasocket.so /usr/bin
sudo chmod +x /usr/bin/premake5
rm premake.tar.gz

premake5 gmake
make
if [ ! -d ~/.lush ]; then
cp -rf ./.lush ~/
fi

# always update example
cp -f ./.lush/scripts/example.lua ~/.lush/scripts/example.lua

# Install the new shell binary to a temporary location
sudo cp ./bin/Debug/lush/lush /usr/bin/lush.new

# Atomically replace the old binary
sudo mv /usr/bin/lush.new /usr/bin/lush

# Ensure the shell is registered in /etc/shells
if ! grep -Fxq "/usr/bin/lush" /etc/shells; then
echo "/usr/bin/lush" | sudo tee -a /etc/shells >/dev/null
fi

# Optionally change the shell
chsh -s /usr/bin/lush

echo "====================="
echo "INSTALLATION FINISHED"
echo "====================="
1 change: 1 addition & 0 deletions lib/compat53
Submodule compat53 added at dfd83b
33 changes: 17 additions & 16 deletions premake5.lua
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
workspace("lush")
configurations({ "Debug", "Release" })

-- lush project
project("lush")
kind("ConsoleApp")
language("C")
targetdir("bin/%{cfg.buildcfg}/lush")

local lua_inc_path = "/usr/include"
local lua_lib_path = "/usr/lib"
links({ "lua5.4" })

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what there an issue with how the linking/including was handled that would make these changes needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there was definitely an issue with how the linking was handled. The original approach using local lua_lib_path = "/usr/lib" was problematic for a few reasons:

The Main Problem:
On most Linux distributions, Lua libraries are installed with versioned names to support multiple Lua versions simultaneously. Instead of a generic liblua.so, you'll typically find files like:

  • liblua5.4.so.5.4.6 (full version)
  • liblua5.4.so.5.4 (minor version symlink)
  • liblua5.4.so (major version symlink)

The generic liblua.so symlink often doesn't exist at all, or if it does, it may point to an unexpected version (like an older Lua 5.1 for backwards compatibility).

So What Was Happening?:
When the build system tried to link using the path-based approach, it was likely doing something equivalent to -L/usr/lib -llua, which tells the linker to look for liblua.so in /usr/lib. This would fail with errors like:

/usr/bin/ld: cannot find -llua: No such file or directory

By switching to links({ "lua5.4" }), I explicitly tell the linker to look for liblua5.4.so, which is the actual filename that exists on the system.
So this,

  • Targets the specific Lua version I want (5.4)
  • Avoids ambiguity about which Lua version to use
  • Works consistently across different distributions
  • Follows the standard naming convention used by package managers

Additional Context:
This is why many professional build systems use pkg-config to handle this automatically:

pkg-config --libs lua5.4    # Returns: -llua5.4

The include path (/usr/include) didn't need changes because header files are typically installed in a predictable location and the compiler was finding them correctly.

The original linking approach assumed a generic liblua.so would exist, but modern package management practices use versioned library names. My fix explicitly targets the correct versioned library, eliminating the ambiguity and build failures.


Also, for some additional context here:
I usually use multiple wsl2 distros, but mostly archlinux.
when I was working on this, I moved from ubuntu LTS wsl2, to archlinux wsl2, so I was able to spot some fragile points in the make system.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologize for not covering that in my pull description. I actually forgot I even made that change. I need to start keeping tabs in a notebook or something of what changes I made and where, for Open Source projects.

if os.findlib("lua5.4") then
lua_inc_path = "/usr/include/lua5.4"
lua_lib_path = "/usr/lib/5.4"
links({ "lua5.4" })
else
links({ "lua" })
end
-- Add all necessary include directories
includedirs({
lua_inc_path,
"lib/hashmap",
"lib/compat53/c-api"
})

includedirs({ lua_inc_path, "lib/hashmap" })
libdirs({ lua_lib_path })
libdirs({ "/usr/lib" })

-- Compile all necessary source files, including the compat library
files({
"src/**.h",
"src/**.c",
"lib/hashmap/**.h",
"lib/hashmap/**.c",
"src/**.h",
"src/**.c",
"lib/hashmap/hashmap.h",
"lib/hashmap/hashmap.c",
"lib/compat53/c-api/compat-5.3.h",
"lib/compat53/c-api/compat-5.3.c"
})
defines({ 'LUSH_VERSION="0.3.2"' })

defines({ 'LUSH_VERSION="0.3.2"', 'COMPAT53_PREFIX=""' })

filter("configurations:Debug")
defines({ "DEBUG" })
Expand Down
Loading
Loading