lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On 2020-01-19 11:20 p.m., Egor Skriptunoff wrote:
On Mon, Jan 20, 2020 at 4:26 AM Soni "They/Them" L. wrote:

    If you had:

    LUA_PATH/foo/init.lua
    LUA_PATH/foo/bar/init.lua
    LUA_PATH/foo/bar/res.txt

    then require("foo.bar", "res.txt") would get you the contents of
    LUA_PATH/foo/bar/res.txt



Should require() cache resources the same way as modules?

not quite the same: yes, but with __mode="v"


Would it be possible to have a module containing only resources without any code?

yes


Could main program have its own resources (files from the same directory)?
require(nil, "res.txt")

evil, but maybe? why not just put them in a submodule?


Resources might be large enough, so it would be better to return a pseudo-file object
instead of huge Lua string.
local res = open_resource("foo.bar", "res.txt")
local data = res:read("*a")
res:close()

tell me, when was the last time you didn't need to keep your app's icons loaded once you loaded them for the first time? in any case __mode="v" should help with this.