Skip to content

Instantly share code, notes, and snippets.

@leiradel
Created January 31, 2021 22:42
Show Gist options
  • Save leiradel/a6816f251927e6216b0a619039ffa2d3 to your computer and use it in GitHub Desktop.
Save leiradel/a6816f251927e6216b0a619039ffa2d3 to your computer and use it in GitHub Desktop.
Auto-run Lua script for HC
local hc = require 'hc'
local lfs = require 'lfs'
local logger, config = hc.logger, hc.config
local coresPath = config:getCoresPath()
logger:info('Looking for Lua scripts in "%s"', coresPath)
for file in lfs.dir(coresPath) do
if file:sub(-4, -1) == '.lua' then
logger:info('Found "%s", running...', file)
local func, err = loadfile(coresPath .. file, 't')
if not func then
logger:error('%s', err)
else
local ok, err = pcall(func)
if not ok then
logger:error('%s', err)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment