lgi-devs / lgi-devs/lgi

Add ability to import lua files from GResources

Open
#168 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
491
Forks
81
PR merge metrics
No merged PRs in 30d

Description

One of the nice features of gjs is that you can import modules from within a GResource. This leads to the common usage of applications shipping a single resource bundle or single executable and avoids doing extra blocking disk io.

Here is a basic implementation of this:


local lgi = require('lgi')
local Gio = lgi.require('Gio')

package.loaders[#package.loaders + 1] = function (str)
  if str:sub(1, 12) == 'resources://' then
    local data = Gio.resources_lookup_data(str:sub(13), Gio.ResourceLookupFlags.NONE)
    if not data then
      return ' - Failed to find data for that path!'
    end

    local str = data:get_data()
    if not str then
      return ' - Failed to get data for that path!'
    end

    local module = loadstring(str)
    if not module then
      return ' - Failed to load string for that path!'
    end
    
    return module
  end
end

local window = require('resources:///org/gnome/Foo/window.lua')

Now I am not overly familiar with the codebase or even Lua so I am unsure where this best belongs but any feedback on the idea would be appreciated.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start by locating the package.loaders integration and the Gio.resources_lookup_data binding shown in the example, then determine how a resources:// module path should be handled. Done should include documented behavior for successful imports and the lookup, data, and loading failures described in the issue, with tests for those cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.