[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [proposal] require resources
- From: Griffin Rock <abcq2@...>
- Date: Mon, 20 Jan 2020 04:44:50 +0000
From: lua-l-bounces@lists.lua.org <lua-l-bounces@lists.lua.org> on behalf of Sean Conner <sean@conman.org>
> Does it ever occur to you to actually *try* to implement your ideas?
> This idea, with a separate resource path, could be done in pure Lua.
> Add a package.rpath (for resource path), then replace require() to look for two
> parameters and handle it appropriately?
how about this:
---------- resource.lua
if not package.rpath then
local path = {}
for file in package.path:gmatch "[^;]*?" do
if not path[file] then
path[file] = 1
table.insert(path,file);
end
end
package.rpath = table.concat(path, ";")
end
local function resource (fname)
local r = package.searchpath(fname, package.rpath, ":")
if r then
return function()
local f = io.open(r)
local t = f:read "*a"
f:close()
return t
end
end
end
table.insert(package.searchers, 2, resource)
return resource
----------
example of use:
require "resource"
icon = require "package:gopher.icon"