I am trying to run the following code
local lgi = require("lgi")
local Gdk = lgi.Gdk
local Gtk = lgi.Gtk
Gtk.init()
-- Create a new window
local window = Gtk.Window({
title = "LGI Test Window",
default_width = 300,
default_height = 200,
on_destroy = Gtk.main_quit,
})
-- Create a label and add it to the window
local label = Gtk.Label({ label = "Hello, LGI!" })
window:add(label)
window:show_all()
Gtk.main()
But this is giving me the following error
lua: /home/username/.luarocks/share/lua/5.3/lgi/core.lua:14: module 'lgi.corelgilua51' not found:
no field package.preload['lgi.corelgilua51']
no file '/home/username/.luarocks/share/lua/5.3/lgi/corelgilua51.lua'
no file '/home/username/.luarocks/share/lua/5.3/lgi/corelgilua51/init.lua'
no file '/usr/local/share/lua/5.3/lgi/corelgilua51.lua'
no file '/usr/local/share/lua/5.3/lgi/corelgilua51/init.lua'
no file '/usr/local/lib/lua/5.3/lgi/corelgilua51.lua'
no file '/usr/local/lib/lua/5.3/lgi/corelgilua51/init.lua'
no file './lgi/corelgilua51.lua'
no file './lgi/corelgilua51/init.lua'
no file '/home/username/.luarocks/lib/lua/5.3/lgi/corelgilua51.so'
no file '/usr/local/lib/lua/5.3/lgi/corelgilua51.so'
no file '/usr/local/lib/lua/5.3/loadall.so'
no file './lgi/corelgilua51.so'
no file '/home/username/.luarocks/lib/lua/5.3/lgi.so'
no file '/usr/local/lib/lua/5.3/lgi.so'
no file '/usr/local/lib/lua/5.3/loadall.so'
no file './lgi.so'
stack traceback:
[C]: in function 'require'
/home/username/.luarocks/share/lua/5.3/lgi/core.lua:14: in main chunk
[C]: in function 'require'
/home/username/.luarocks/share/lua/5.3/lgi/init.lua:19: in main chunk
[C]: in function 'require'
/home/username/.luarocks/share/lua/5.3/lgi.lua:19: in main chunk
[C]: in function 'require'
init2.lua:1: in main chunk
I have already set LUA_PATH
and LUA_CPATH
, but installing lgi
from luarocks
does not have the corelgilua51
, what could be the issues, the lgi only contain the following files:-
drwxr-xr-x. 1 username username 226 Nov 15 13:01 .
drwxr-xr-x. 1 username username 30 Nov 15 13:05 ..
-rw-r--r--. 1 username username 15928 Nov 15 13:01 class.lua
-rw-r--r--. 1 username username 11130 Nov 15 13:01 component.lua
-rw-r--r--. 1 username username 761 Nov 15 13:01 core.lua
-rw-r--r--. 1 username username 3319 Nov 15 13:01 enum.lua
-rw-r--r--. 1 username username 5939 Nov 15 13:01 ffi.lua
-rw-r--r--. 1 username username 3403 Nov 15 13:01 init.lua
-rw-r--r--. 1 username username 1090 Nov 15 13:01 log.lua
-rw-r--r--. 1 username username 6217 Nov 15 13:01 namespace.lua
drwxr-xr-x. 1 username username 524 Nov 15 13:01 override
-rw-r--r--. 1 username username 1591 Nov 15 13:01 package.lua
-rw-r--r--. 1 username username 7088 Nov 15 13:01 record.lua
-rw-r--r--. 1 username username 15 Nov 15 13:01 version.lua
lua version 5.3.6
, not upgraded to 5.4 as a project I am trying to use requires a lua version less than 5.4, how can a module be absent when installing from luarocks
and any help would be appreciated. Please ask for any other information if required.
The reason for this question is that the lib directory in the lgi's Makefile is hardcoded as /usr/local/lib/lua/5.1
.
PREFIX = /usr/local
LUA_VERSION=5.1
LUA_LIBDIR = $(PREFIX)/lib/lua/$(LUA_VERSION)
LUA_SHAREDIR = $(PREFIX)/share/lua/$(LUA_VERSION)
...
mkdir -p $(DESTDIR)$(LUA_LIBDIR)/lgi
cp $(CORE) $(DESTDIR)$(LUA_LIBDIR)/lgi
As you can see in the question, when you use it in another version of Lua, the directory it searches for is /usr/local/lib/lua/5.3/lgi.so
, which resulted in the error. The solution can be to modify the value of LUA_VERSION
in the Makefile, or copy the output file to the correct directory, or change package.searchpath
.