Blog: 2025-02-15

From razwiki
Revision as of 00:15, 15 February 2025 by Razzi (talk | contribs) (Created page with "I figure before I get to writing fennel and stuff I should understand the host platform: namely lua! I have lua 5.4 installed First thing: I wanted to install the lua socket library to make a lua irc server. However the default install tried to write to /usr/ which failed with a permission error. Better to write to ~/.local <pre> $ cat ~/.config/lua/luarocks-5.4.lua rocks_trees = { home .. "/.local/lib/lua"; } lua_interpreter = "lua5.4" </pre> Also need to set it...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

I figure before I get to writing fennel and stuff I should understand the host platform: namely lua!

I have lua 5.4 installed

First thing: I wanted to install the lua socket library to make a lua irc server. However the default install tried to write to /usr/ which failed with a permission error. Better to write to ~/.local

$ cat ~/.config/lua/luarocks-5.4.lua
rocks_trees = {
  home .. "/.local/lib/lua";
}

lua_interpreter = "lua5.4"

Also need to set it up in ~/.profile:

export LUAROCKS_CONFIG="$HOME/.config/lua/luarocks-5.4.lua"
export LUA_PATH="$LUA_PATH;$HOME/.local/lib/lua/share/lua/5.4/?.lua"
export LUA_CPATH="$HOME/.local/lib/lua/lib/lua/5.4/?.so"

Ok then I can get the library:

$ luarocks install luasocket

and require it:

$ lua
Lua 5.4.7  Copyright (C) 1994-2024 Lua.org, PUC-Rio
> require('socket')
table: 0x7fb742c07480	/Users/razzi/.local/lib/lua/share/lua/5.4/socket.lua

And this works, however I don't have history in the lua repl !!

Luckily https://github.com/hoelzro/lua-repl provides history !

Just needed to also install linenoise as well for it to have command line editing:

$ luarocks install linenoise
Installing https://luarocks.org/linenoise-0.9-1.rockspec

linenoise 0.9-1 depends on lua >= 5.1 (5.4-1 provided by VM: success)
env MACOSX_DEPLOYMENT_TARGET=11.0 gcc -O2 -fPIC -I/usr/local/opt/lua/include/lua5.4 -c linenoise.c -o linenoise.o
env MACOSX_DEPLOYMENT_TARGET=11.0 gcc -O2 -fPIC -I/usr/local/opt/lua/include/lua5.4 -c linenoiselib.c -o linenoiselib.o
env MACOSX_DEPLOYMENT_TARGET=11.0 gcc -O2 -fPIC -I/usr/local/opt/lua/include/lua5.4 -c encodings/utf8.c -o encodings/utf8.o
env MACOSX_DEPLOYMENT_TARGET=11.0 gcc  -bundle -undefined dynamic_lookup -all_load -o /var/folders/f5/gj618n116zd11_yml7p22dww0000gn/T/luarocks_build-linenoise-0.9-1-4513498/linenoise.so linenoise.o linenoiselib.o encodings/utf8.o
linenoise 0.9-1 is now installed in /Users/razzi/.local/lib/lua (license: MIT/X11)