mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-09 04:49:39 -10:00
This allows to use the built-in lua "require" function with our file system. This will help organize complicated scripts and it will also allow to use libraries which were designed for this system. To enable this change, this includes a new mechanism which allows to load scripts from the default file system so that the files don't need to be included in every mod. The default files can be overridden by a mod if a special mod-table option has been set, similar to how external shaders are handled right now.
37 lines
677 B
Lua
37 lines
677 B
Lua
local exts = {
|
|
"",
|
|
".lua",
|
|
".lc"
|
|
}
|
|
|
|
local function cfileLoader(name)
|
|
local file = nil
|
|
|
|
for i,v in ipairs(exts) do
|
|
local real_name = name .. v
|
|
file = cf.openFile(real_name, "r", "data/scripts")
|
|
|
|
if (file:isValid()) then
|
|
name = real_name
|
|
break;
|
|
end
|
|
end
|
|
|
|
if (file == nil or not file:isValid()) then
|
|
return "Module '" .. name .. "' is not known by the CFile system"
|
|
end
|
|
|
|
local content = file:read("*a")
|
|
file:close()
|
|
|
|
local func, err = loadstring(content, name)
|
|
|
|
if err then
|
|
return err
|
|
end
|
|
|
|
return func
|
|
end
|
|
|
|
table.insert(package.loaders, 2, cfileLoader)
|