Using it, you're able to do the following:
Code: Select all
-- insert just before normal loader
-- glsl is the file extension, newShader is the callback (gets the file content)
table.insert(package.loaders, 2, extension_loader("glsl", love.graphics.newShader))
function love.load()
myshader = require("some.mod.path!glsl")
-- note the path, myshader is a shader object
end
As such, as this a bad idea?
Code: Select all
local extension_loader = function(ext, cb)
return function(modname)
-- only handle paths that end in !ext (eg. my.mod.effect!glsl)
if (not string.find(modname, "!"..ext.."$")) then
return nil
end
-- normalize the path
local modpath = modname
modpath = string.gsub(modpath, "%.", "/")
modpath = string.gsub(modpath, "!", ".")
-- read and return a partially applied callback
local content, _ = love.filesystem.read(modpath)
if content then
return function() cb(content) end, modpath
else
return "no file found named `"..modpath.."` (using `"..ext.."` loader)"
end
end
end
- Jon