From 0ed9543d50f909344463fecf41eb3a84366c5e80 Mon Sep 17 00:00:00 2001 From: brachyonic Date: Sun, 10 Feb 2013 12:49:44 -0500 Subject: [PATCH] Now chdirs into the quirks folder before executing lua quirks, allowing require() to be used without having to preprend 'quirks.', just a bit cleaner --- luaquirks.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/luaquirks.py b/luaquirks.py index 32ef26a..8cefbfd 100644 --- a/luaquirks.py +++ b/luaquirks.py @@ -10,9 +10,20 @@ class LuaQuirks(ScriptQuirks): def loadModule(self, name, filename): if lua is None: return None - fullname = os.path.join('quirks', name) - lua.globals().package.loaded[fullname] = None - return lua.require(fullname) + + lua.globals().package.loaded[name] = None + + CurrentDir = os.getcwd() + os.chdir('quirks') + try: + print("a") + return lua.require(name) + except Error as e: + print(e) + return None + finally: + print("back") + os.chdir(CurrentDir) def getExtension(self): return '.lua' @@ -27,11 +38,19 @@ class LuaQuirks(ScriptQuirks): self.name = name def __call__(self, text): - return self.module.commands[self.name](lua.globals().tostring(text)) + CurrentDir = os.getcwd() + os.chdir('quirks') + try: + return self.module.commands[self.name](lua.globals().tostring(text)) + except: + return None + finally: + os.chdir(CurrentDir) for name in module.commands: + CommandWrapper = Wrapper(module,name) try: - if not isinstance(module.commands[name]("test"), basestring): + if not isinstance(CommandWrapper("test"), basestring): raise Exception except: print "Quirk malformed: %s" % (name) @@ -40,5 +59,5 @@ class LuaQuirks(ScriptQuirks): msgbox.setText("Quirk malformed: %s" % (name)) msgbox.exec_() else: - self.quirks[name] = Wrapper(module, name) + self.quirks[name] = CommandWrapper