Skip to content

Commit

Permalink
gmod-addon AddCSLuaFile jestronaut files
Browse files Browse the repository at this point in the history
  • Loading branch information
luttje committed Dec 2, 2024
1 parent 02fe22f commit aa58545
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion gmod-addon/lua/autorun/sh_jestronaut.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
AddCSLuaFile()
AddCSLuaFile("sh_jestronaut_gmod_reporter.lua")
AddCSLuaFile("sh_jestronaut_gmod_test.lua")
AddCSLuaFile("jestronaut.lua")

--- Recursively adds all files in a directory to be included by AddCSLuaFile
--- @param path string
local function addDirectory(path)
local files, directories = file.Find(path .. "/*", "LUA")

for _, file in ipairs(files) do
AddCSLuaFile(path .. "/" .. file)
end

for _, directory in ipairs(directories) do
addDirectory(path .. "/" .. directory)
end
end

addDirectory("jestronaut")
addDirectory("tests")

-- Gmod's require doesn't return any values, so we replace require with include while loading jestronaut
-- This is a hacky way to make jestronaut work with Gmod
local function callWithRequireCompat(func)
Expand All @@ -11,7 +33,7 @@ local function callWithRequireCompat(func)
if (file.Exists(path .. ".lua", "LUA")) then
alreadyRequired[path] = { include(path .. ".lua") }
else
Msg("Could not find file: " .. path)
MsgN("Could not find file: " .. path)
return false
end
end
Expand Down

0 comments on commit aa58545

Please sign in to comment.