From 70ecca9cc050690cf4c5707c171cf8516223d11e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Sat, 15 Aug 2020 22:46:16 -0700 Subject: [PATCH] I might want to return more than functions later --- MWSE/mods/celediel/MoreAttentiveGuards/main.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/MWSE/mods/celediel/MoreAttentiveGuards/main.lua b/MWSE/mods/celediel/MoreAttentiveGuards/main.lua index af8969f..8f78678 100644 --- a/MWSE/mods/celediel/MoreAttentiveGuards/main.lua +++ b/MWSE/mods/celediel/MoreAttentiveGuards/main.lua @@ -2,12 +2,16 @@ local sneak = require("celediel.MoreAttentiveGuards.sneak") local combat = require("celediel.MoreAttentiveGuards.combat") local common = require("celediel.MoreAttentiveGuards.common") -local eventPattern = "on(%u)" +-- in order for this to work, functions in returned table must follow pattern: onEventName +local function registerFunctionEvents(t) + for name, func in pairs(t) do + if type(func) == "function" then event.register(name:gsub("on(%u)", string.lower), func) end + end +end local function onInitialized() - -- in order for this to work, everything in returned table must be functions named onEventName - for name, func in pairs(sneak) do event.register(name:gsub(eventPattern, string.lower), func) end - for name, func in pairs(combat) do event.register(name:gsub(eventPattern, string.lower), func) end + registerFunctionEvents(sneak) + registerFunctionEvents(combat) common.log("Successfully initialized") end