From 75ad207d0b6db75e5678f3bb018aeb8672a3271c Mon Sep 17 00:00:00 2001 From: javalikescript Date: Sun, 5 Jan 2025 11:25:52 +0100 Subject: [PATCH] Allow extension to require core --- lha/Extension.lua | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lha/Extension.lua b/lha/Extension.lua index f357b13..437fe46 100644 --- a/lha/Extension.lua +++ b/lha/Extension.lua @@ -174,14 +174,12 @@ return require('jls.lang.class').create(require('jls.util.EventPublisher'), func end end - function extension:require(name, base) - local n - if base then - n = name - else - n = string.format('%s.%s', self.dir:getName(), name) + function extension:require(name, isCore) + local dir = self.dir + if isCore then + dir = self.engine.lhaExtensionsDir end - return loader.load(n, self.dir:getParent()) + return loader.load(name, dir:getPath()) end function extension:subscribePollEvent(fn, minIntervalSec, lastPollSec) @@ -477,7 +475,12 @@ return require('jls.lang.class').create(require('jls.util.EventPublisher'), func end function extension:getScriptFile() - return File:new(self.dir, self.manifest and self.manifest.script or 'init.lua') + local script = self.manifest and self.manifest.script or 'init.lua' + local path = string.match(script, '^//(.+)$') + if path then + return File:new(self.engine.lhaExtensionsDir, path) + end + return File:new(self.dir, script) end function extension:loadManifest()